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.

Microsoft Graph PowerShell
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 -NoTypeInformation

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

AuthorRole
Priyanshu UpadhyaySolution Architect, Microsoft 365 and Azure
Disclaimer. These samples are provided as is, without warranty of any kind. Read and test every script in a non-production tenant before you run it, and run reports before any command that changes or deletes data.