Jump to content

Get inactive AAD Users

From wiki.oeser.name
Revision as of 16:20, 4 January 2024 by Udo (talk | contribs) (Created page with "Category: Powershell Script Examples Install-Module Microsoft.Graph -Scope CurrentUser Connect-MgGraph $inactiveDate = (Get-Date).AddDays(-90) $users = Get-MgUser -All:...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Install-Module Microsoft.Graph -Scope CurrentUser Connect-MgGraph

$inactiveDate = (Get-Date).AddDays(-90)

$users = Get-MgUser -All:$true -Property Id, DisplayName, UserPrincipalName, UserType, SignInActivity | Where-Object { $_.AccountEnabled -eq $true }

$inactiveUsers = $users | Where-Object {

   $_.SignInActivity.LastSignInDateTime -lt $inactiveDate

} | Select-Object DisplayName, UserPrincipalName, UserType

$inactiveUsers