[英]How to assign AAD Group to an Enterprise App?
i would like to know how to assign one or multiple groups to an application?我想知道如何将一个或多个组分配给一个应用程序?
I've tried this but im getting an error: Get-AzureADGroup : Error occurred while executing GetGroup我已经尝试过了,但出现错误:Get-AzureADGroup:执行 GetGroup 时发生错误
connect-azuread
$GroupName = "TEST"
$app_name = "Intranet"
$app_role_name = "Default Access"
# Get the group to assign
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
Your error indicate clearly the part which is failing.您的错误清楚地表明了失败的部分。 There is no
ObjectId
provided to the last statement because your $AADGroup.ObjectId
is $null
没有为最后一条语句提供
ObjectId
,因为您的$AADGroup.ObjectId
是$null
Looking at an excerpt of your code:查看您的代码摘录:
$GroupName = 'test'
$AADGROUP = Get-AzureADGroup -ObjectId $GroupName
#...
# Assign the group to the app role
New-AzureADGroupAppRoleAssignment -ObjectId $AADGROUP.ObjectId -PrincipalId $AADGROUP.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
$GroupName
is a very bad name for this variable if you are using it along with the Get-AzureADGroup -ObjectId $GroupName
statement right after.如果将
$GroupName
GroupName 与之后的Get-AzureADGroup -ObjectId $GroupName
语句一起使用,则此变量的名称非常糟糕。 It won't work.它行不通。
-ObjectId
is expecting the object ID GUID of the group, not its name (You might be already doing it correctly, my assumption come from your variable name). -ObjectId
期望组的对象 ID GUID,而不是其名称(您可能已经正确执行此操作,我的假设来自您的变量名称)。
That would explain where you don't have any group returned and why the error occur.这将解释您没有返回任何组的位置以及发生错误的原因。 If you want to use the group name, you will need to call the
Get-AzureADGroup
with -SearchString
instead of -ObjectId
.如果要使用组名,则需要使用
-SearchString
而不是 -ObjectId 调用Get-AzureADGroup
-ObjectId
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.