在Powershell中将用户分配到Active Directory本机应用程序 - ' C.

时间:2018-02-06 12:42:15

标签: powershell azure active-directory

我无法在门户网站中添加它,因为它是一个原生应用,但他们不允许这样做。我尝试按照this页面上的步骤进行操作:

# Get the service principal of the app to assign the user to
$servicePrincipal = Get-AzureADServicePrincipal -SearchString "<Your app's display name>"

# Get the user to be assigned
$user = Get-AzureADUser -searchstring "<Your user's UPN>"

# Create the user app role assignment
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $servicePrincipal.ObjectId -Id ([Guid]::Empty)

我收到以下错误:New-AzureADUserAppRoleAssignment : Cannot bind argument to parameter 'ObjectId' because it is null.

但是当我检查它时,它说不是真的:

PS C:\Windows\system32> $user.ObjectId -ne $null
False

我做错了什么?

1 个答案:

答案 0 :(得分:0)

由于双重否定,您混淆了逻辑结果。例如

$null -ne $null

返回“false”,因为$ null不等于$ null不正确。您的测试告诉您每个错误$ user.ObjectID确实是null。您可能需要确认Get-AzureADUser正在将对象返回到$user