Before assigning or auditing Azure AD directory roles, administrators often need a complete list of all available roles, along with their definitions — whether they are Microsoft-defined (built-in) or custom-created. This script leverages the Get-MgRoleManagementDirectoryRoleDefinition cmdlet from Microsoft Graph PowerShell to retrieve and present these roles clearly.
# Connect to Microsoft Graph with necessary permissions
Connect-MgGraph -Scopes "RoleManagement.Read.Directory"
# Retrieve all directory role definitions
$roleDefinitions = Get-MgRoleManagementDirectoryRoleDefinition -All
# Format the output with useful columns
$formatted = $roleDefinitions | Select-Object `
Id,
DisplayName,
Description,
IsBuiltIn,
RolePermissions
# Display results in table format
$formatted | Format-Table -AutoSize
# Optional: Export to CSV
# $formatted | Export-Csv -Path "AllDirectoryRoleDefinitions.csv" -NoTypeInformation
Here’s what this script does step by step:
Uses Connect-MgGraph with the required scope (RoleManagement.Read.Directory) to query role-related metadata.
The Get-MgRoleManagementDirectoryRoleDefinition -All cmdlet returns every directory role available in Azure AD — including both built-in roles (like Global Administrator) and custom roles.
Using Select-Object, the script extracts relevant properties:
Results are shown as a clean table, with an optional export to CSV for documentation or audits.
$roleDefinitions | Where-Object { $_.IsBuiltIn -eq $true }
$roleDefinitions | Where-Object { $_.IsBuiltIn -eq $false }
$roleDefinitions | Where-Object { $_.DisplayName -like "*Admin*" }
$role.RolePermissions.AllowedResourceActions
Here’s why this script is valuable to Microsoft 365 admins and security teams:
Error Message | Cause | Solution |
Access Denied | Missing required Graph permissions | Use -Scopes "RoleManagement.Read.Directory" when connecting |
The term 'Get-MgRoleManagementDirectoryRoleDefinition' is not recognized | Graph module not installed or loaded correctly | Run Install-Module Microsoft.Graph -Scope CurrentUser and Import-Module Microsoft.Graph |
Empty Output | No roles returned or filtering too early | Use -All and ensure role permissions are enabled |
The Get-MgRoleManagementDirectoryRoleDefinition cmdlet is your go-to tool for discovering all assignable roles in Azure AD — both built-in and custom. Whether you're assigning roles, auditing access, or managing custom role creation, this script gives you clear visibility into the complete RBAC role catalog available in your tenant.
It works perfectly alongside:
By integrating this script into your admin workflow, you can confidently manage and govern directory roles with precision.
© m365corner.com. All Rights Reserved. Design by HTML Codex