The Get-MgRoleManagementDirectoryRoleAssignment cmdlet is a powerful Graph PowerShell tool that allows administrators to retrieve role assignments within the Microsoft Entra (Azure AD) directory. This includes identifying who has been assigned to which role, a crucial aspect of enforcing least privilege and auditing access in any Microsoft 365 environment.
This article dives into the cmdlet’s syntax, real-world usage examples, admin tips, and more.
Get-MgRoleManagementDirectoryRoleAssignment [-UnifiedRoleAssignmentId <String>] [-Filter <String>] [-All]
Key Parameters:
Get-MgRoleManagementDirectoryRoleAssignment -All
This lists all current role assignments in your tenant, across all roles and users.
Get-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId "RhIJaeggVkqqTQZgdbKnqLD_j_s5eBFImpF5Q7fm2iU-1"
This retrieves details of a specific assignment, useful for audits or verifying role access.
Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq 'b1368af9-0f0a-41cf-85b7-63ef13eabc87'" -All
This filters role assignments where the user, group, or service principal ID matches the specified value.
Error | Cause | Solution |
Access Denied or Insufficient privileges to complete the operation. | You don't have the necessary Graph API permissions. | Use an account with RoleManagement.Read.Directory or Directory.Read.All scopes. |
Cannot bind parameter because parameter 'UnifiedRoleAssignmentId' is null or empty. | You passed a blank or invalid ID to the -UnifiedRoleAssignmentId parameter. | Ensure you pass a valid ID string for that parameter. |
The term 'Get-MgRoleManagementDirectoryRoleAssignment' is not recognized... | Module or cmdlet not installed. | Run Install-Module Microsoft.Graph -Scope CurrentUser and import it again. |
How do I find out what a specific role assignment ID refers to?
Use Get-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId
Can I find all users with a specific role like Global Administrator?
Yes! First, use Get-MgRoleManagementDirectoryRoleDefinition to get the roleDefinitionId for "Global Administrator", then filter:
Get-MgRoleManagementDirectoryRoleAssignment -Filter "roleDefinitionId eq '...' " -All
Is this the same as role assignments shown in the Entra admin center?
Yes. This cmdlet retrieves the same underlying data that appears in Microsoft Entra ID → Roles and Administrators → Role assignments.
The Get-MgRoleManagementDirectoryRoleAssignment cmdlet is essential for any Microsoft 365 administrator looking to monitor, audit, or report on directory role assignments. It offers flexibility to query everything from all assignments to specific users or roles, giving you clear insight into who has access to what in your tenant.
By combining this cmdlet with others like Get-MgUser, Get-MgGroup, and Get-MgRoleManagementDirectoryRoleDefinition, you can build a powerful admin access monitoring system.
© m365corner.com. All Rights Reserved. Design by HTML Codex