What It Does
The script signs in as your app registration and checks each account in BreakGlassAccounts. It changes nothing. It checks that the account exists, that it is enabled, that it is excluded from every enabled Conditional Access policy that applies to users, and that it has had no sign-in in the last SignInLookbackDays days (default 7).
Exclusion counts when the account is excluded directly or through a group it belongs to, nested groups included. Report-only policies and policies that apply only to guests are ignored. A policy that excludes a directory role the account holds is not resolved: it is counted as not excluding the account. The row gives a count of policies.
Any failed check ends the run in an alert, and the answer names the accounts and what failed. A sign-in alerts because nobody should use these accounts day to day. Set AllowSignIn=true for the days you try the accounts yourself: the sign-in count still shows up to 50 events from the first page, but does not alert.
It keeps no state. A second run reads the tenant again and reports the same result until you fix the problem. Run it on a schedule and alert on exit 1.
Before You Run It
- Name the break-glass accounts in BreakGlassAccounts, with their user principal names.
- Create an app registration with User.Read.All, Policy.Read.All, AuditLog.Read.All and GroupMember.Read.All, with admin consent. The sign-in check needs Entra ID P1.
- Put the app's certificate on the computer that runs the script and use its thumbprint.
- Set AllowSignIn=true on the days you sign in to the accounts on purpose.
- If a policy excludes the account by role, review that exclusion yourself. This check counts the policy as not excluding the account.
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: "Break-glass: [emergency account 2 sign-in]: not excluded from 2 Conditional Access polic(ies); [emergency account 1 sign-in]: signed in 1 time(s) in 7 days"
- 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).
- BreakGlassAccounts: The break-glass accounts' user principal names, separated by comma, semicolon or new line. Required.
- SignInLookbackDays: Alert on a sign-in within this many days. Whole number, 1 to 30. Default 7.
- AllowSignIn: true to list sign-ins but not alert on them (for the days when you test the accounts). Default false.
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.