Get inactive AAD Users: Difference between revisions
Appearance
Created page with "Category: Powershell Script Examples Install-Module Microsoft.Graph -Scope CurrentUser Connect-MgGraph $inactiveDate = (Get-Date).AddDays(-90) $users = Get-MgUser -All:..." |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category: Powershell Script Examples]] | [[Category: Powershell Script Examples]] | ||
==Connect to Tenant== | |||
Install-Module Microsoft.Graph -Scope CurrentUser | Install-Module Microsoft.Graph -Scope CurrentUser (if not there allready) | ||
Connect-MgGraph | Connect-MgGraph -Scopes "User.Read.All", "Directory.Read.All", "Auditlog.Read.All" | ||
== Set inactivity Date == | |||
$ | $inactiveDate = (Get-Date).AddDays(-90) | ||
== Get all Users == | |||
$inactiveUsers | $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 | |||
Latest revision as of 16:29, 4 January 2024
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