Security · 2 tools
Find users who have not signed in for 90 days
Summary
Finds enabled member accounts with no interactive or non-interactive sign-in in the last 90 days, a common first step for licence reclamation and before migration waves.
Implementation
Choose your tool. Your choice is remembered on other samples.
Connect-MgGraph -Scopes User.Read.All, AuditLog.Read.All -NoWelcome
$cutoff = (Get-Date).AddDays(-90)
Get-MgUser -All -Filter "accountEnabled eq true and userType eq 'Member'" `
-Property Id, DisplayName, UserPrincipalName, SignInActivity, AssignedLicenses, CreatedDateTime |
Where-Object {
$last = @($_.SignInActivity.LastSignInDateTime, $_.SignInActivity.LastNonInteractiveSignInDateTime) |
Where-Object { $_ } | Sort-Object -Descending | Select-Object -First 1
(-not $last -and $_.CreatedDateTime -lt $cutoff) -or ($last -and $last -lt $cutoff)
} |
Select-Object DisplayName, UserPrincipalName, CreatedDateTime,
@{ n = "LastSignIn"; e = { $_.SignInActivity.LastSignInDateTime } },
@{ n = "LastNonInteractive"; e = { $_.SignInActivity.LastNonInteractiveSignInDateTime } },
@{ n = "Licences"; e = { $_.AssignedLicenses.Count } } |
Export-Csv .\inactive-users.csv -NoTypeInformationGET https://graph.microsoft.com/v1.0/users?$filter=signInActivity/lastSignInDateTime le 2026-09-01T00:00:00Z&$select=displayName,userPrincipalName,signInActivity
# Permissions: User.Read.All and AuditLog.Read.All
# Follow @odata.nextLink until it is absent to read every page.Prerequisites
- Graph scopes User.Read.All and AuditLog.Read.All
- Microsoft Entra ID P1 (signInActivity needs it)
Output
CSV of inactive users with last sign-in dates and licences.
Contributors
| Author | Role |
|---|---|
| Priyanshu Upadhyay | Solution Architect, Microsoft 365 and Azure |
InnovaticT