Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion InactiveUsersLast90Days.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ $endDate = (Get-Date).ToString('MM/dd/yyyy')
$allUsers = @()
$allUsers = Get-MsolUser -All -EnabledFilter EnabledOnly | Select UserPrincipalName

$PageCounter=1 #Set it to 1 initially since we will start with the first page.
$loggedOnUsers = @()
$loggedOnUsers = Search-UnifiedAuditLog -StartDate $startDate -EndDate $endDate -Operations UserLoggedIn, PasswordLogonInitialAuthUsingPassword, UserLoginFailed -ResultSize 5000
Do{
Write-Verbose -Message "Pulling Page $PageCounter"
$loggedOnUsers += Search-UnifiedAuditLog -StartDate $startDate -EndDate $endDate -Operations UserLoggedIn, PasswordLogonInitialAuthUsingPassword, UserLoginFailed -ResultSize 5000 -SessionId "Inactive Users Report - 90 days" -SessionCommand ReturnNextPreviewPage
$PageCounter++
}While($loggedOnUsers.count%5000 -eq 0) #Since the command will return 5000 results at once, the modulo should always be 0 until we get the last set.

$inactiveInLastThreeMonthsUsers = @()
$inactiveInLastThreeMonthsUsers = $allUsers.UserPrincipalName | where {$loggedOnUsers.UserIds -NotContains $_}
Expand Down