When managing permissions across Microsoft 365 and Azure AD, it's vital to understand who holds which role and at what scope. The Get-MgRoleManagementDirectoryRoleAssignment cmdlet from the Microsoft Graph PowerShell SDK lets you query and analyze these role assignments in a standardized way.
This article dives deep into the cmdlet’s syntax, examples, output structure, comparisons, and practical use cases.
Get-MgRoleManagementDirectoryRoleAssignment
Get-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId
This cmdlet retrieves Azure AD role assignments, showing you which users, groups, or service principals have been granted specific directory roles (like Global Admin, User Admin, etc.).
It returns data in the form of unifiedRoleAssignment objects — a standardized model used by Microsoft Graph to represent role assignments across different services like Azure AD and Azure RBAC.
The unifiedRoleAssignment object is a Graph API abstraction that contains key details about:
This unification allows a consistent way to manage RBAC across the Microsoft ecosystem.
Get-MgRoleManagementDirectoryRoleAssignment
This returns a list of all role assignments in your directory. To extract additional details (e.g., names), you'd combine it with Get-MgUser, Get-MgGroup, or Get-MgServicePrincipal.
Get-MgRoleManagementDirectoryRoleAssignment -UnifiedRoleAssignmentId "lAPpYvVpN0KRkAEhdxReECvy-ge2vZRIgYix4HUDS_4-1"
This fetches the properties and relationships of a specific role assignment by its unique ID.
Each result is a unifiedRoleAssignment object containing:
To map the IDs to actual names, additional Graph queries are needed .
Feature | Get-MgDirectoryRole | Get-MgRoleManagementDirectoryRoleAssignment |
Get-MgRoleManagementDirectoryRoleAssignment | Lists activated directory roles | Lists assignments of roles to users/groups/SPs |
Object type | directoryRole | unifiedRoleAssignment |
Shows who is assigned? | ❌ No | ✅ Yes |
Shows role definitions? | ✅ (for activated roles) | ✅ (referenced via RoleDefinitionId) |
Supports group/SP assignments? | ❌ | ✅ |
Supports scope (e.g., apps)? | ❌ | ✅ (via DirectoryScopeId) |
PIM eligibility/activation? | ❌ | ❌ (Use Schedule* cmdlets instead) |
Only roles that have been activated (i.e., assigned to at least one user or app) will appear in the Get-MgDirectoryRole results. To activate a role, use Enable-MgDirectoryRole with the corresponding role template ID.
Each object returned by Get-MgDirectoryRoleMember
includes an @odata.type
property. Use this to distinguish between users (microsoft.graph.user
) and service principals (microsoft.graph.servicePrincipal
).
Yes. First retrieve the role ID using a filter like:
(Get-MgDirectoryRole | Where-Object {$_.DisplayName -eq "Global Administrator"}).Id
Then use Get-MgDirectoryRoleMember -RoleId
to fetch assigned members.
New-MgDirectoryRole
a one-time process?Yes, activating a directory role with New-MgDirectoryRole
is a one-time action per tenant per role template. Once activated, the role will remain visible to Graph queries unless manually removed or deactivated.
Connect-MgGraph -Scopes "RoleManagement.Read.Directory", "Directory.Read.All"
Error Message | Cause | Solution |
Access Denied | Missing permissions | Add scopes: "RoleManagement.Read.Directory" and "Directory.Read.All" |
Resource not found | Invalid or deleted PrincipalId or role assignment | Ensure valid assignment IDs; check for deleted objects |
Empty results | Role assignments not present or filtered incorrectly | Use -All and remove any filters |
Get-MgDirectoryRole
to list available roles.New-MgDirectoryRole -DirectoryRoleTemplateId <TemplateId>
before querying assignments.
@odata.type
Get-MgDirectoryRoleMember -RoleId <RoleId>
@odata.type
property to identify whether it's a user or an application identity.
The Get-MgRoleManagementDirectoryRoleAssignment cmdlet is essential for role governance in Microsoft 365. By providing a unified and scalable way to review who has access to what, it helps admins enforce the principle of least privilege across the tenant.
Pair it with other Graph cmdlets like Get-MgUser, Get-MgGroup, and Get-MgServicePrincipal to produce clear, human-readable reports. If you're serious about managing administrative access — this cmdlet is your starting point.
© m365corner.com. All Rights Reserved. Design by HTML Codex