Find and Clean Up Inactive User Accounts
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
- License: reading the sign-in activity (
signInActivity) through Microsoft Graph needs Microsoft Entra ID P1 or P2 (List users, example 11 (opens in a new tab)). Access reviews scoped to inactive users need Microsoft Entra ID Governance or Microsoft Entra Suite (Create an access review (opens in a new tab)). - Roles: Reports Reader is the least-privileged role to read activity data (Prerequisites (opens in a new tab)). Deleting and restoring users needs at least User Administrator; User Administrators can delete non-admin users, Helpdesk Administrators and other User Administrators, while deleting other admins takes Privileged Authentication Administrator (Delete a user (opens in a new tab), Restore users (opens in a new tab)).
- Graph scopes for the report:
User.Read.AllandAuditLog.Read.All(Prerequisites (opens in a new tab)).
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
- 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)).
- 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.
- Run the report-first script (below) and export to CSV.
- 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.
- Disable first. Clear Account enabled on the user's properties (Account enabled (opens in a new tab)); for scripted changes,
User.EnableDisableAccount.AllplusUser.Read.Allis the least-privileged combination for writingaccountEnabled(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)). - 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)).
- 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
signInActivityfilters don't combine. It supports$filterwitheq,ne,not,geandle, but not together with any other filterable property, and it's only returned when you$selector$filteron it (List users (opens in a new tab)). Filter on dates server-side, then filter user type or enabled state in PowerShell.- Page size drops to 500 when you select or filter on
signInActivity(List users (opens in a new tab)).-Allhandles paging. - Blank isn't proof of abandonment. A brand-new account has no sign-in yet; that's why the script also checks
createdDateTime.lastSuccessfulSignInDateTimeis also blank for accounts whose last success was before December 1, 2023, because it isn't backfilled. - Deleting synced users in the cloud doesn't stick. Microsoft Entra ID isn't the source of authority, and sync may restore the user on the next cycle (Restore users (opens in a new tab)).
- The 30-day clock is hard. Deleted users stay restorable for 30 days; after that, permanent deletion starts automatically and can't be stopped, and nobody, including Microsoft Support, can bring the account back (Restore users (opens in a new tab)).
- Restores can put you over on licenses. A restored user gets back the licenses it had, even if none are available (Restore a recently deleted user (opens in a new tab)).
Check it worked
- Rerun the report: every remaining
Candidate = Truerow is either disabled, excluded on purpose (break-glass, service needs) or scheduled for deletion. - Entra ID > Users > Deleted users lists what you removed, with time left to restore (View your restorable users (opens in a new tab)).
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 GuidesIs this still accurate?
Spotted something outdated or wrong on this page? Tell us in a sentence. The page address is sent with it.