What It Does
The script signs in as your app registration, reads the Entra sign-in log for the last LookbackDays days (default 30) and keeps the sign-ins whose client is a legacy one. It writes one row per user, client type and app with the counts, the last time seen and the most frequent IP address. It changes nothing, and as a Report it never alerts. If the log query returns no matching sign-ins, the report is OK with an empty table.
The log is read newest first, 1,000 at a time, and it stops at MaxSignIns legacy sign-ins (default 20,000) so a busy tenant does not run for hours. The answer says when it stopped early. A busy tenant can also time out on a wide window: narrow LookbackDays.
The log keeps 30 days at most and needs Entra ID P1 or P2. The log stores the client names in several spellings, so the script filters on every spelling it knows and the rows show the string the log returned. A new spelling shows up as no rows, not an error. Non-interactive legacy sign-ins may be missing from this endpoint.
It keeps no state, so a second run reads the log again. Use the rows to tell each user and device owner what to change before you block legacy sign-in.
Before You Run It
- Create an app registration with the Graph application permission AuditLog.Read.All and give admin consent.
- Check the client tenant has Entra ID P1 or P2, or the sign-in log cannot be read.
- Put the app's certificate on the computer that runs the script and use its thumbprint.
- Start with the default 30 days, and narrow LookbackDays if it times out.
- Use ExportPath to save the rows and work through the users before you block legacy sign-in.
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 5 minutes.
- Example answer: "142 legacy sign-in(s) by 6 user(s) in 30 days; clients: IMAP4 (97), Authenticated SMTP (45)"
- 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).
- LookbackDays: How many days of the sign-in log to read. Whole number, 1 to 30. Default 30.
- MaxSignIns: Stop after this many legacy sign-ins. Whole number, 100 to 200000. Default 20000.
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.