[英]Azure function / powershell: Trying to find ObjectID of user by doing lookup of email address. "Connect-AzureAD is not recognized"
I have been banging my head against the wall trying to get this to work.我一直在用头撞墙,试图让它发挥作用。
Just to be clear, I am not running this locally .为了清楚起见,我不是在本地运行它。 This runs fine when I run it locally in powershell cli.
当我在 powershell cli 本地运行它时,它运行良好。
I am running this as an Azure Function App.我将其作为 Azure Function 应用程序运行。 The weird thing is that a few lines above this I have similar code to connect to PnPOnline - that works fine.
奇怪的是,在这上面的几行我有类似的代码来连接到 PnPOnline - 工作正常。
Goal : I need to be able to pass an email address to AD and retrieve the ObjectID of that user.目标:我需要能够将 email 地址传递给 AD 并检索该用户的 ObjectID。 Again, works fine locally.
再次,在本地工作正常。
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName,
$(convertto-securestring $Password -asplaintext -force)
Import-Module AzureAD
Connect-AzureAD -Credentials $cred
The error:错误:
The term 'Connect-AzureAD' is not recognized as the name of a cmdlet, function, script file, or operable program.
Any help would be GREATLY appreciated.任何帮助将不胜感激。
The term 'Connect-AzureAD' is not recognized as the name of a cmdlet, function, script file, or operable program.
术语“Connect-AzureAD”未被识别为 cmdlet、function、脚本文件或可运行程序的名称。
The error occurs because AzureAD module is not installed.发生错误是因为未安装 AzureAD 模块。
You can install AzureAD module using the below command:您可以使用以下命令安装 AzureAD 模块:
Install-Module -Name AzureAD
Once the AzureAD module is installed, you can import the AzureAD module in your powershell script using below command:安装 AzureAD 模块后,您可以使用以下命令在 powershell 脚本中导入 AzureAD 模块:
Import-Module AzureAD
Now you can connect to the Azure AD and get the user object id using the below script:现在您可以使用以下脚本连接到 Azure AD 并获取用户 object id:
Import-Module AzureAD
$secpasswd = $Password | ConvertTo-SecureString -AsPlainText -Force;$cred = New-Object Management.Automation.PSCredential ($UserName, $secpasswd);
Connect-AzureAD -Credential $cred;
$ADUser = Get-AzureADUser -Filter "EmailAddress -eq 'someEmail@something.com'"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.