After getting the app role assignments to a service principal:
Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId ServicePrincipalId
I want to get the value for each app role. The response includes an app role ID and a resource ID for each assigned app role.
I can get the app roles for an application as follows, but then I would first need to map the service principal's object ID (resource ID) to the object ID of the associated application:
(Get-MgApplication -ApplicationId ApplicationId).AppRoles
Is there an easier way?
To fetch the app role's value given an app role ID in Entra ID using Microsoft Graph PowerShell, make use of below script:
I granted few application API permissions to the Microsoft Entra ID application:
$ServicePrincipalId = "ServicePrincipalObjectID"
$AppRoleAssignments = Get-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $ServicePrincipalId
$AssignedRoles = @()
foreach ($Assignment in $AppRoleAssignments) {
$ResourceId = $Assignment.ResourceId
$AppRoleId = $Assignment.AppRoleId
$ServicePrincipal = Get-MgServicePrincipal -ServicePrincipalId $ResourceId
$AppRole = $ServicePrincipal.AppRoles | Where-Object { $_.Id -eq $AppRoleId }
if ($AppRole) {
$AssignedRoles += [PSCustomObject]@{
'App Role ID' = $AppRole.Id
'App Role Display Name' = $AppRole.DisplayName
'App Role Value' = $AppRole.Value
}
}
}
$AssignedRoles | Format-Table -AutoSize