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.