Skip to content
Menu

Sign-In History of One User

Reads the Entra sign-in log for one user over the last LookbackDays and gives each sign-in with app, IP address, country and result, plus the countries seen.

Sign-in history of one user is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Sign-in history of one user. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, 11, Server 2016+, with the app certificate; runs as SYSTEM or a user
NeedsPowerShell 5.1; Graph: AuditLog.Read.All; Entra ID P1
Read-onlyReads, changes nothing

What It Does

The script signs in as your app registration and reads the Entra sign-in log for the one user in UserPrincipalName, over the last LookbackDays days (default 7), newest first, up to MaxRows rows (default 500). Use it when a user may be compromised: which apps, from which IP addresses and countries, and whether each sign-in worked.

The answer counts the sign-ins and failures it returned and lists countries with counts. A warning tells you if MaxRows stopped the report early. It is a Report: it never alerts, so read the rows. It changes nothing in the tenant.

The sign-in log needs Entra ID P1 or P2 and keeps 30 days at most, so LookbackDays stops at 30. Interactive sign-ins and successful federated sign-ins are in this log. Microsoft's page does not say that non-interactive and service-principal sign-ins are, so they may be missing.

It keeps no state, so a second run reads the log again. A property missing from a row is shown empty.

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.
  • Give the user's exact sign-in name, such as [account sign-in].
  • Use ExportPath to save the rows as a file for the ticket.

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: "[account sign-in]: 63 sign-in(s) in 7 days, 4 failed; countries: CA (60), RO (3)"
  • 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).
  • UserPrincipalName: The user's sign-in name, for example [account sign-in]. Required.
  • LookbackDays: How many days to read. Whole number, 1 to 30. Default 7.
  • MaxRows: The most sign-ins to list. Whole number, 10 to 5000. Default 500.

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.

The Script

get-user-signin-history.ps1 · 988 lines · 54.8 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.