Skip to main content
KBY Technologies Logo

Auditing Privileged Role Assignments in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell

List Microsoft Entra ID role assignments read-only with Get-MgRoleManagementDirectoryRoleAssignment and count privileged and Global Administrator roles safely.

KBY Technologies10 min readFoundation13 min
Auditing Privileged Role Assignments in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Before you begin

  • A Microsoft Entra tenant you are allowed to inspect, ideally a training tenant.
  • The Microsoft Graph PowerShell SDK with the Microsoft.Graph.Identity.Governance module.
  • The RoleManagement.Read.Directory delegated permission, and no wider one.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

To see who holds privileged roles in , sign in with the read-only RoleManagement.Read.Directory permission, list every role assignment with Get-MgRoleManagementDirectoryRoleAssignment -All -ExpandProperty "roleDefinition", and count the assignments whose role definition is privileged. Microsoft recommends fewer than five Global Administrators and fewer than ten privileged role assignments, so those two counts are your first measures. Nothing here changes the tenant.

An assignment on its own is only three identifiers: who, which role and where. Read all three, and separate what the list proves from what you still need to ask. It is a close cousin of listing disabled users with read-only Microsoft Graph PowerShell, using the same safe habits on a different question.

#By the end you can

  • Explain what a role assignment joins together: a principal, a role definition and a scope.
  • Connect to Microsoft Graph PowerShell with one read-only permission and confirm what the session was granted.
  • List every role assignment, with its role definition attached, and group the result by role.
  • Count privileged assignments and Global Administrator assignments and compare them with Microsoft’s published guidance.
  • Say what the list proves, what it only suggests and who to hand it to.

#Before you begin

  • A Microsoft Entra tenant you are allowed to inspect, ideally a training tenant rather than production.
  • The Microsoft Graph PowerShell SDK, which provides Connect-MgGraph, and its Microsoft.Graph.Identity.Governance module, which provides the role cmdlets.
  • An account that can consent to, or has been given, the RoleManagement.Read.Directory delegated permission. Microsoft lists it first among the permissions “from least to most privileged” for the cmdlets used here.

Use that permission and no other. The same cmdlet page also lists RoleManagement.ReadWrite.Directory and Directory.ReadWrite.All, which can change things. A tool that only reads should never be given the ability to write.

#How access is recorded in Microsoft Entra ID

Microsoft Entra role-based access control grants a specific set of permissions, over a specific scope, for a specific period of time. Microsoft describes the aim as least privilege: give administrators exactly the permission they need and no more, because limiting roles and scopes limits what is at risk if an account is compromised. There are over 65 built-in roles, and you can create custom ones.

In Microsoft Graph, one grant is a unifiedRoleAssignment with three properties that matter here:

  • principalId identifies who holds the access. Supported principals are users, role-assignable groups and service principals, so an assignment is not always a person.
  • roleDefinitionId identifies the role, which you can expand to read its display name and whether it is built in or privileged.
  • directoryScopeId identifies the directory object that is the scope of the assignment, which sets the set of resources the principal can act on.

#
The three parts of an assignment

Loading diagram...
Laptop screen displaying code and performance graphs with eyeglasses resting on the keyboard.
Photo by Daniil Komov on Pexels

#
What ‘privileged’ means

A role definition has an isPrivileged flag. Microsoft Entra ID treats a role as privileged if it contains at least one sensitive resource action, and that applies only to actions in the microsoft.directory namespace. The flag can be null, and Microsoft is explicit that a null value “indicates that the privileged classification is unavailable, not that the role is nonprivileged”. So $null is not a clean bill of health. In the admin center, privileged roles carry a PRIVILEGED label.

#
Two thresholds worth knowing

Microsoft recommends assigning Global Administrator to fewer than five people. A Global Administrators alert card appears on the Overview page when there are five or more privileged Global Administrator role assignments.

It also recommends fewer than ten privileged role assignments overall, and exceeding ten shows a warning on the Roles and administrators page. Microsoft also recommends two cloud-only emergency access accounts permanently assigned Global Administrator, so a count of two is not automatically a problem.

#A worked example: the count nobody had looked at

Suppose an administrator at a small training company is asked how many people can change authentication policy. The example is invented to show the reasoning; the numbers are not from a real tenant. They run the listing in the exercise below and group by role. Illustrative output:

Illustrative output: assignments grouped by role (invented numbers)
RoleAssignmentsPrivileged flag
Global Administrator6True
User Administrator4True
Helpdesk Administrator3False
Reports Reader2False

Reading it step by step shows how to separate fact from inference.

  1. Fact: six Global Administrator assignments. That is above Microsoft’s fewer-than-five guidance, so it is worth a conversation. It is not yet a finding, because two of the six might be the emergency access accounts and one might be a group.
  2. Fact: ten assignments carry the privileged flag, which is not fewer than ten. Microsoft says exceeding ten shows a warning, so ten itself sits on the edge. This is the kind of result you report as a number with its date, not as a verdict.
  3. Inference to test, not assume: that all six hold the role permanently. This list says an assignment exists. It does not say whether the person activates it only when needed through Privileged Identity Management, so check that separately.

Following along? Tap a step’s number to tick it off.

The right output is a short note: the counts, the date, the permission used, the three open questions and the person who owns role changes. The note does not say anyone has too much access. It says what was found and what is unknown.

#Exercise: list and count your tenant’s role assignments

Objective. Produce counts of role assignments by role, of privileged assignments and of Global Administrator assignments, plus a note of what the list cannot tell you. Safe setup. Every command reads. Do not run any cmdlet whose name begins New-, Update- or Remove- against role assignments.

  1. Connect with one read-only scope: Connect-MgGraph -Scopes "RoleManagement.Read.Directory". Sign in when prompted and consent only if the prompt names that permission.
  2. Check what you were granted with Get-MgContext. Look at the Scopes and AuthType values. You expect the scope you asked for and a delegated session.
  3. List every assignment with its role attached: $assignments = Get-MgRoleManagementDirectoryRoleAssignment -All -ExpandProperty "roleDefinition". The -All switch lists all pages, so you do not silently stop at the first page.
  4. Count them: $assignments.Count.
  5. Group them by role: $assignments | Group-Object { $_.RoleDefinition.DisplayName } | Sort-Object Count -Descending | Select-Object Count, Name.
  6. Count the privileged ones: ($assignments | Where-Object { $_.RoleDefinition.IsPrivileged }).Count. Then count the unclassified ones with ($assignments | Where-Object { $null -eq $_.RoleDefinition.IsPrivileged }).Count, because a null flag means the classification is unavailable, not that the role is safe.
  7. Count Global Administrator assignments: ($assignments | Where-Object { $_.RoleDefinition.DisplayName -eq "Global Administrator" }).Count.
  8. End the session with Disconnect-MgGraph.

Expected evidence. Step 2 shows your requested scope and a delegated auth type. Step 4 gives a whole number. Step 5 gives one row per role in use, and Global Administrator usually appears. Steps 6 and 7 give whole numbers you compare with the thresholds above.

Pass condition. You can write one sentence of the form “On [date], with [permission], the tenant had [n] role assignments, [p] on privileged roles and [g] Global Administrator assignments”, and a second naming one thing the list does not tell you.

Stop condition. Stop if the sign-in asks for a permission with Write in its name, or if you find yourself about to run a cmdlet that changes an assignment.

Cleanup. Nothing changed. Run Disconnect-MgGraph, because the sign-in persists across PowerShell sessions until you do.

For a follow-up, -ExpandProperty also accepts principal, which the Graph documentation says is supported for the assigned principal. The cmdlet page does not say whether the read-only scope alone is enough for it. If it is refused, report the principalId values to someone with directory read access. Do not widen your own permission to find out.

A collection of assorted rusty padlocks, displaying a blend of colors and textures.
Photo by Goszton on Pexels

#How to check that the list told the truth

A count is only as good as what it covers. Work through these checks before you report a number.

  • Did you list every page? Without -All you can report a partial count. Compare $assignments.Count with a second run to see it is stable.
  • Did the role definition come through? If display names are blank, the -ExpandProperty value was wrong. Re-run it and check one row by hand against Entra ID > Roles & admins > All roles in the admin center.
  • Is the count about people? It counts assignments. A group counts once however many people are in it, and the same person holding two roles counts twice.
  • Does it include everything? Time-limited access through Privileged Identity Management is a separate feature, and Microsoft describes eligible assignments that a user activates for a limited time. Do not assume this list shows them. Confirm in PIM, then say which you checked.
  • Is the permission what you think? Get-MgContext shows the scopes in your session. If a wider scope is there, disconnect and sign in again with one.

#What goes wrong when you read role assignments

  • Counting accounts instead of assignments. Six rows are not necessarily six people. Resolve the principalId values before you say a number of people.
  • Treating null as safe. A null privileged flag means the classification is unavailable.
  • Judging by the role name alone. The same role at a narrower scope reaches fewer resources. Read directoryScopeId before you conclude, and ask how administrative units are used.
  • Ignoring synced accounts. Microsoft advises using cloud-native accounts for role assignments, because a compromised on-premises account can compromise Entra resources too. Note which principals are synced if you can see it.
  • Flagging the emergency accounts. Two cloud-only emergency access accounts holding Global Administrator are recommended. Ask before reporting them as a problem.
  • Fixing it on the spot. Removing someone’s role from this session is a change with its own review, of the current assignments and rollback. It is outside this exercise.

#Taking this into production

Run the listing under your normal change and access process, record the date, tenant, permission and counts, and keep the output as evidence rather than a screenshot. Hand findings to whoever owns role changes, and let them decide. Microsoft’s own guidance sets the review path: least privilege, just-in-time access through Privileged Identity Management, multifactor authentication for every administrator account and recurring access reviews.

The same reading habit helps elsewhere. If an account is under suspicion, learn what its roles allow before you act, then follow revoking a user’s sessions after a suspected compromise.

If a privileged account is failing to sign in, start from finding why a sign-in failed in the Entra sign-in logs. For the escalation boundary, remember that a read-only role listing never justifies an unreviewed change, and that Microsoft documents the privileged-roles guidance and the cmdlet pages as the references to check for the module version you run.

#What to remember

  • An assignment joins a principal, a role definition and a scope. Read all three.
  • Use RoleManagement.Read.Directory only, confirm it with Get-MgContext and end with Disconnect-MgGraph.
  • Use -All and -ExpandProperty "roleDefinition" so the count is complete and readable.
  • Fewer than five Global Administrators and fewer than ten privileged assignments are Microsoft’s guidance, not a pass mark for your tenant.
  • A null privileged flag is unknown, an assignment is not a person, and the list is not proof of how access is used.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Found this useful? Follow KBY for more like it.

Reader Interaction

Comments

Add a thoughtful note on Auditing Privileged Role Assignments in Microsoft Entra ID with Read-Only Microsoft Graph PowerShell. Comments are checked for spam and held for moderation before appearing.

Loading comments...

More from KBY that goes with this article.

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Build practical engineering skills.

Receive new lessons, learning paths, practical exercises and early-career guidance.