The Get-MgServicePrincipalAppRoleAssignedTo cmdlet retrieves the users, groups, and service principals that have been assigned a specific app role from a resource application. This is useful for auditing who has permission to use the application's defined roles.
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "AppRoleAssignment.Read.All"
Run the Graph PowerShell command below to retrieve users, groups, and service principals that have been assigned a specific app role. Replace <service-principal-id> with the required service principal object ID:
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId <service-principal-id>
This Graph PowerShell command retrieves a list of principals that have been assigned a role for the specific resource application represented by the provided service principal ID:
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890"
This Graph PowerShell command restricts output to five assignments:
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890" -Top 5
This Graph PowerShell command shows only assignments where the principal type is User:
Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890" -Filter "principalType eq 'User'"
The following are some essential parameters that can be used along with the Get-MgServicePrincipalAppRoleAssignedTo command:
| Parameters | Description |
|---|---|
| -ServicePrincipalId | Specifies the service principal's object ID |
| -Top | Limits the number of results returned |
| -Filter | Filters results based on specified criteria |
| -All | Retrieves all results without paging |
| -Property | Selects certain properties to be returned in the output |
ADManager Plus, an identity governance and administration solution with comprehensive Microsoft Entra ID management and reporting capabilities, simplifies complex admin tasks from a single, user-friendly console: