Library

Guides Quick Fixes Scripts Find a Guide

Tools

Error Decoder Assessment Baselines Free Tools Service status What's Changed

More

AI Certifications For MSPs Recommended Gear Field Kit FAQ About Contact Get Assessment

Find and Clean Up Inactive User Accounts

EntraReady Guides · Practical Microsoft 365 & Entra ID
Last reviewed:
Last verified against Microsoft Learn:

User accounts aren't always deleted when people leave, and they stick around long after anyone uses them, and Microsoft treats these obsolete accounts as a security risk (Manage inactive user accounts (opens in a new tab)). There's no built-in "inactive users" report, but every user object carries its last sign-in times. This guide builds a report-first list, then disables, reviews and deletes in an order you can undo.

Use it when: you're tidying a tenant you've inherited, preparing for an audit or license true-up, or before building dynamic groups (stale users inflate membership; see Dynamic membership groups). For guests specifically, see Guest access cleanup and Recurring access reviews for guests.

Before you start

Know which timestamp you're reading

Property What it records
lastSignInDateTime Last interactive sign-in attempt, successful or failed. Failed attempts count, so it can overstate real use (signInActivity (opens in a new tab)).
lastNonInteractiveSignInDateTime Last non-interactive attempt, such as a client acting for the user.
lastSuccessfulSignInDateTime Most recent successful interactive or non-interactive sign-in. Microsoft says to use this one to tell when an account was truly accessed. Available from December 1, 2023 and not backfilled (signInActivity (opens in a new tab)).

A blank lastSignInDateTime means the account never attempted a sign-in, or the last attempt was before April 2020. The values can take up to 24 hours to update (Considerations (opens in a new tab)).

Step by step

  1. Pick your window. Learn notes that in many organizations a reasonable window is 90 to 180 days, after allowing for vacations and other legitimate absences (What are inactive accounts (opens in a new tab)).
  2. Quick look in the portal. As Reports Reader, go to Entra ID > Users > Manage view > Edit columns, add Last interactive sign-in time, then use Add filter with the <= operator and your cutoff date (Find the last sign-in time for all users (opens in a new tab)). This column is interactive only, so confirm candidates with the report below.
  3. Run the report-first script (below) and export to CSV.
  4. Triage with the owners. Ask whether the person still works there, still needs the access, and whether the account is needed for anything else (How to address inactive users (opens in a new tab)). Exclude your break-glass accounts, which may legitimately go months without a sign-in.
  5. Disable first. Clear Account enabled on the user's properties (Account enabled (opens in a new tab)); for scripted changes, User.EnableDisableAccount.All plus User.Read.All is the least-privileged combination for writing accountEnabled (Permissions for specific scenarios (opens in a new tab)). For synced users, make the change in on-premises Active Directory, which is their source of authority, and let sync carry it (Delete a user note (opens in a new tab)).
  6. Optional: let reviewers decide. With ID Governance, create an access review of a group and tick Inactive users (on tenant level) with Days inactive (up to 730). Recently created users aren't pulled into scope (Create an access review (opens in a new tab)). The No sign-in within 30 days decision helper recommends Deny for users without a sign-in in the last 30 days (Review recommendations (opens in a new tab)).
  7. Delete after a grace period. In Entra ID > Users, select the user and Delete user. Their licenses are freed (Delete a user (opens in a new tab)).

Report-first PowerShell

Read-only. Scopes: User.Read.All, AuditLog.Read.All. Needs Microsoft Entra ID P1/P2 for signInActivity.

Connect-MgGraph -Scopes "User.Read.All","AuditLog.Read.All"
$cutoff = (Get-Date).ToUniversalTime().AddDays(-90)
Get-MgUser -All -Property "displayName,userPrincipalName,userType,accountEnabled,onPremisesSyncEnabled,createdDateTime,signInActivity" |
ForEach-Object {
$last = $_.SignInActivity.LastSuccessfulSignInDateTime
[pscustomobject]@{
DisplayName           = $_.DisplayName
UPN                   = $_.UserPrincipalName
UserType              = $_.UserType
Enabled               = $_.AccountEnabled
Synced                = $_.OnPremisesSyncEnabled
Created               = $_.CreatedDateTime
LastSuccessful        = $last
LastInteractive       = $_.SignInActivity.LastSignInDateTime
LastNonInteractive    = $_.SignInActivity.LastNonInteractiveSignInDateTime
Candidate             = ($_.CreatedDateTime -lt $cutoff) -and (-not $last -or $last -lt $cutoff)
}
} | Export-Csv .\inactive-users-report.csv -NoTypeInformation

Graph equivalent for a filtered list: GET https://graph.microsoft.com/v1.0/users?$filter=signInActivity/lastSuccessfulSignInDateTime le 2026-08-29T00:00:00Z (Microsoft Graph tab (opens in a new tab)). That query returns the users but not their sign-in details.

Gotchas

Check it worked

Roll back

Re-enable a disabled account by setting Account enabled back on. Within 30 days of deletion, restore from Deleted users > Restore user as at least User Administrator; the account's properties come back with it (Restore users (opens in a new tab)).

Related on EntraReady: Guest access cleanup, Recurring access reviews for guests, Too many Global Admins, Break-glass accounts, Clean up stale devices.

← All Guides

Is this still accurate?

Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.

Reports go to the EntraReady inbox. Please don’t include passwords or tenant secrets.