What It Does
The script signs in as your app registration and reads the Entra directory audit log, role management category, for the last LookbackHours hours (default 24). A successful event named Add member to role, or Add eligible member to role for an assignment made in Privileged Identity Management, ends the run in an alert. Each row reports the actor and recipient from the audit event, plus the role name or ID when available. The recipient can be a user, app or group. It changes nothing.
Events whose actor is in IgnoreActors are skipped, for example the break-glass or provisioning account you expect to assign roles. List users by sign-in name or apps by name.
It keeps no state between runs, so schedule it more often than LookbackHours or an assignment can fall between two runs. A second run inside the window reports the same assignments again.
The activity names and the category come from Microsoft's audit activity reference. If a tenant words an activity differently, the script reports no events, not an error. Pair it with get-entra-admin-roles for the full list of who holds a role.
Before You Run It
- Create an app registration with the Graph application permission AuditLog.Read.All and give admin consent.
- Put the app's certificate on the computer that runs the script and use its thumbprint.
- Schedule it more often than LookbackHours. Hourly with the 24 hour default is safe.
- Add the accounts that legitimately assign roles to IgnoreActors.
- Alert on exit 1 and have a person check each name against a ticket.
Type and Risk
- Type: Monitor. It checks one condition. It exits 1 when it finds the problem, so your RMM can alert on it, 0 when all is well, and 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: "2 admin role assignment(s) in the last 24 h: [another user sign-in] got Global Administrator from [account sign-in]"
- 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).
- LookbackHours: How far back to look. Whole number, 1 to 720. Default 24.
- IgnoreActors: User principal names or app names whose role assignments are expected, separated by comma, semicolon or new line. Default empty.
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.