Jump to content

Get inactive AAD Users

From wiki.oeser.name
Revision as of 16:29, 4 January 2024 by Udo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Connect to Tenant

Install-Module Microsoft.Graph -Scope CurrentUser (if not there allready)
Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All", "Auditlog.Read.All"

Set inactivity Date

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

Get all Users

$users = Get-MgUser -All:$true -Property Id, DisplayName, UserPrincipalName, UserType, SignInActivity 

== select users who not singin after inactivity date

$inactiveUsers = $users | Where-Object { $_.SignInActivity.LastSignInDateTime -lt $inactiveDate} | Select-Object DisplayName, UserPrincipalName, UserType

list users

$inactiveUsers