What It Does
This script is read-only. It signs in as your app registration, with a certificate or a ClientSecret from a secure RMM field, and reads the Microsoft Entra directory audit log for the last LookbackHours hours (1 to 720, default 24). It looks in the user management category for two events: a user registered security info, and an admin registered security info.
Each successful registration alerts. The row names the user it was added to, the method when the log says what it was, who did it and the IP address. Failed attempts, and the event that only says registration is complete, are not counted. The Method or IpAddress column can be empty when the log does not fill it, and if a tenant words the event differently the script reports no events, not an error.
People registering their first method after you create their account alert too. List them in IgnoreUsers, or run the check a few hours after onboarding. The script keeps no state, so run it on a schedule shorter than LookbackHours so no registration falls between two runs. A second run reports the same registrations again for as long as they are inside the window.
If an alert is real, run reset-user-mfa-methods and invoke-compromised-account-containment.
Before You Run It
- Create an app registration with the Microsoft Graph application permission AuditLog.Read.All and grant admin consent.
- Put the app's certificate, with its private key, on the computer that runs the script, or put the secret in a secure RMM field named ClientSecret.
- Set LookbackHours longer than the time between your scheduled runs.
- Add new hires to IgnoreUsers, or run the check a few hours after onboarding.
- Know your next step for a real alert: reset-user-mfa-methods and invoke-compromised-account-containment.
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 MFA method registration(s) in the last 24 h: ann@contoso.com (Fido2) from 203.0.113.9"
- 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.
- IgnoreUsers: Sign-in names whose registrations are expected (new hires), 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.