简体   繁体   中英

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

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

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. 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).

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM