Skip to content
Menu

Who Holds Admin Roles in Microsoft 365

One row per directory role assignment: role, member, active or eligible, scope and end date. It counts Global Administrators and warns outside 2 to 4.

Who holds admin roles in Microsoft 365 is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Who holds admin roles in Microsoft 365. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: RoleManagement.Read.Directory; Entra ID P2 for the eligible list
Read-onlyReads, changes nothing

What It Does

The script signs in as your app registration and lists every Entra directory role assignment: the role, the member (user, app or group), whether the assignment is Active or Eligible, its scope and, for an eligible assignment, when it ends. It changes nothing.

It counts the Global Administrators, meaning distinct users with the role active. Apps and groups are listed but not counted. It warns when there are fewer than 2 or more than 4, the range Microsoft recommends. Members of a group that holds a role are not expanded: the group is listed as the member.

Eligible assignments need Entra ID P2 or Governance. Where the tenant has no PIM, the eligible part is skipped with a warning and the active list is still reported. IncludeEligible=false lists active assignments only. If a member cannot be expanded, its ID is shown and the run still succeeds.

A Report cannot raise an alert. To be told when someone is made an admin, schedule test-new-admin-assignments. It keeps no state, so a second run reads the roles again.

Before You Run It

  • Create an app registration with the Graph application permission RoleManagement.Read.Directory and give admin consent.
  • Put the app's certificate on the computer that runs the script and use its thumbprint.
  • Entra ID P2 is needed to see eligible assignments. Without it you get the active list and a warning.
  • Read the Global Administrator count in the answer, and check any app or group holding a role.
  • Use ExportPath to keep a dated copy for the client's review.

Type and Risk

  • Type: Report. It collects facts into a table and never alerts. It exits 0, or 2 when it could not run.
  • Risk: Low. It reads and changes nothing.
  • Restart: It never restarts the machine.
  • Typical run: Under 1 minute.
  • Example answer: "9 admin role assignment(s) in 5 role(s); 3 Global Administrator(s) (2 to 4 is recommended); 2 eligible"
  • Tested before listing with Windows PowerShell 5.1, run as SYSTEM, against its own test cases and a Microsoft 365 Business Premium test tenant.

Inputs

Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.

  • TenantId: The client tenant: its ID (a GUID) or a domain such as contoso.onmicrosoft.com. Required.
  • ClientId: The Application (client) ID of the app registration that holds the Graph permissions. Required.
  • CertificateThumbprint: Thumbprint of the app's certificate (private key in LocalMachine\My or CurrentUser\My). Preferred. When empty, the app secret is read from the environment variable ClientSecret (a secure/hidden RMM field; never an argument).
  • IncludeEligible: true (default) to also list PIM-eligible assignments. false to list active assignments only.

Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.

License

Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.

The Script

get-entra-admin-roles.ps1 · 1022 lines · 57.4 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.