(Get-AzureRmADUser -Mail $user).Id
返回null 如何为服务主体赋予从Azure Active Directory读取的正确权限?
答案 0 :(得分:0)
通过Install-Module AzureAD
[1]
连接到Azure Active Directory
Connect-AzureAD
获取“目录读者”角色的ID
$roleId = (Get-AzureADDirectoryRole | where-object {$_.DisplayName -eq "Directory Readers"}).Objectid
获取服务主体对象ID
$spObjectId = (Get-AzureADServicePrincipal -SearchString "spName").ObjectId
将服务主体添加到“目录读取器”角色
Add-AzureADDirectoryRoleMember -ObjectId $roleId -RefObjectId $spObjectId
检查是否已将SP分配给目录读取者角色
Get-AzureADDirectoryRoleMember -ObjectId $roleId | Where-Object {$_.ObjectId -eq $spObjectId}
如果您想在以后从角色中删除服务主体
Remove-AzureADDirectoryRoleMember -ObjectId $roleId -MemberId $spObjectId
另请参阅[2]
[2] Using a Service Principal to connect to a directory in PowerShell