Skip to main content
Microsoft Entra ID · PowerShell 7.6

Members who haven't signed in for 90 days

Which member (non-guest) user accounts have not signed in successfully for 90 days (or the number of days you pass), including members who never signed in at all?

Script

#Requires -Modules Microsoft.Graph.Authentication, Microsoft.Graph.Users
# Member accounts with no successful sign-in in the last -Days days (or never). Read-only.
param(
    [int]$Days = 90,
    [switch]$IncludeDisabled
)

Connect-MgGraph -Scopes 'User.Read.All', 'AuditLog.Read.All' -NoWelcome

$cutoff = (Get-Date).AddDays(-$Days)

Get-MgUser -All -Filter "userType eq 'Member'" -Property 'id', 'displayName', 'userPrincipalName', 'createdDateTime', 'accountEnabled', 'onPremisesSyncEnabled', 'signInActivity' |
    Where-Object { $IncludeDisabled -or $_.AccountEnabled } |
    Where-Object { $null -eq $_.CreatedDateTime -or $_.CreatedDateTime -lt $cutoff } |
    ForEach-Object {
        [pscustomobject]@{
            DisplayName          = $_.DisplayName
            UserPrincipalName    = $_.UserPrincipalName
            AccountEnabled       = $_.AccountEnabled
            SyncedFromAD         = [bool]$_.OnPremisesSyncEnabled
            CreatedDateTime      = $_.CreatedDateTime
            LastSuccessfulSignIn = $_.SignInActivity.LastSuccessfulSignInDateTime
        }
    } |
    Where-Object { $null -eq $_.LastSuccessfulSignIn -or $_.LastSuccessfulSignIn -lt $cutoff } |
    Sort-Object LastSuccessfulSignIn

Checked automatically against Microsoft's published cmdlet reference. KBY hasn't run it in your tenant; run it in a test environment first.

Reading the output

  • Uses signInActivity.lastSuccessfulSignInDateTime, the most recent successful interactive or non-interactive sign-in. Microsoft documents that signInActivity needs a Microsoft Entra ID P1 or P2 licence and the AuditLog.Read.All permission, and names Reports Reader as the least privileged role for reading activity logs.
  • An empty LastSuccessfulSignIn means the account has no recorded successful sign-in: it never signed in, or last did so before Microsoft started keeping the value. Microsoft says the last sign-in date can take up to 24 hours to update, so a very recent sign-in may not show yet.
  • Only enabled accounts are listed. Add -IncludeDisabled to see disabled ones too, for example to find disabled accounts that were never cleaned up.
  • Accounts created inside the window are left out, because they haven't had -Days to sign in yet. Accounts with no createdDateTime (some created before June 2018) are included.
  • Member accounts include ones that aren't people: shared mailbox, room and service accounts, which often never sign in. Check what an account is for before you disable it. Accounts marked SyncedFromAD are managed in on-premises Active Directory.
  • Guests are left out; the guest accounts script covers them.

Sources

The Microsoft reference page for every cmdlet the script calls, plus the API and product pages behind each permission and caveat.

All scripts