Getting the app role lists for users in Microsoft Entra ID is necessary for admins to ensure that users have the appropriate permissions within enterprise apps, preventing unauthorized access or privilege escalation. This visibility helps enforce least privilege access, streamline role audits, and maintain compliance with security policies.
Before using the Get-MgUserAppRoleAssignment cmdlet, ensure the following:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Directory.Read.All"
The Get-MgUserAppRoleAssignment cmdlet can be used in Microsoft Graph PowerShell to fetch Microsoft Entra ID user app role assignments. Here's the syntax:
Get-MgUserAppRoleAssignment
-UserId <String>
[-ExpandProperty <String[]>]
[-Property <String[]>]
[-Filter <String>]
[-Search <String>]
[-Skip <Int32>]
[-Sort <String[]>]
[-Top <Int32>]
[-ConsistencyLevel <String>]
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-PageSize <Int32>]
[-All]
[-CountVariable <String>]
[-ProgressAction <ActionPreference>]
[<CommonParameters>]
Listing all the assigned app roles for a particular user
Get-MgUserAppRoleAssignment -UserId <"user_id"> | Format-List Id, AppRoleID, CreationTimeStamp, PrincipalDisplayName,PrincipalId, PrincipalType, ResourceDisplayName
In this command, replace user_id with the user's ID for whom you would like to list all the assigned app roles.
The following table contains some parameters that can be used along with the Get-MgUserAppRoleAssignment command to fetch Microsoft Entra ID user app role assignments efficiently.
| Parameters | Description |
|---|---|
| -All | This parameter retrieves all user app role assignments without default pagination limits. |
| -Filter | This parameter filters user app role assignments based on attributes and values. |
| -UserId | This parameter retrieves user app role assignments based on their unique identifiers, such as user principal name or object ID. |
| -Property | This parameter retrieves specific attributes of user app role assignments. |
| -ConsistencyLevel | This enables advanced query capabilities for improved performance. |
While Microsoft Graph PowerShell allows domain ownership verification using Confirm-MgDomain, there are some limitations: