Jump to content

Get inactive AAD Users: Difference between revisions

From wiki.oeser.name
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:..."
 
Udo (talk | contribs)
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"


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


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


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


$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