In Microsoft Entra ID, users can be assigned application roles (app roles) to access enterprise applications. While listing every assignment is useful, many scenarios only require a quick count of how many app role assignments a user has.
The Get-MgUserAppRoleAssignmentCount cmdlet is designed for this purpose—it returns a numeric count of app role assignments for a given user, making it lightweight and ideal for audits, reporting, and automation.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Get-MgUserAppRoleAssignmentCount -UserId <String> [-ConsistencyLevel <String>]
Key Parameter:
Get-MgUserAppRoleAssignmentCount
Explanation:
When the cmdlet is run without explicitly providing -UserId, the console prompts you to enter the user identifier. After input, it returns the total number of app role assignments for that user.
Get-MgUserAppRoleAssignmentCount ` -UserId tks@w4l0s.onmicrosoft.com ` -ConsistencyLevel Eventual
Explanation:
Returns the total count of app role assignments for the specified user, explicitly passing the user principal name and setting the required consistency level to ensure the query succeeds.
Get-MgUserAppRoleAssignmentCount ` -UserId tks@w4l0s.onmicrosoft.com ` -ConsistencyLevel Eventual | Export-CSV "d:/approleassignments2.csv"
Explanation:
Exports the numeric result to a CSV file. This is useful when collecting counts across users for reporting or audit documentation.
| Error / Message | Cause | Solution |
| Request_UnsupportedQuery | Missing consistency level | Re-run the command with -ConsistencyLevel Eventual. |
| Authorization_RequestDenied | Insufficient permissions | Ensure AppRoleAssignment.Read.All or Directory.Read.All is granted. |
| ResourceNotFound | Invalid UserId | Verify the user’s UPN or object ID. |
| Output is 0 unexpectedly | User has no direct app role assignments | Confirm whether access is granted via group-based assignments instead. |
| Cmdlet not recognized | Microsoft.Graph module missing | Install or update using Install-Module Microsoft.Graph. |
The Get-MgUserAppRoleAssignmentCount cmdlet provides a fast and efficient way to determine how many application roles are assigned to a user in Microsoft Entra ID. By returning only a count, it reduces overhead and is well suited for audits, governance checks, and automation workflows where performance and simplicity matter.
© m365corner.com. All Rights Reserved. Design by HTML Codex