Inactive AD accounts

From UVOO Tech Wiki
Revision as of 16:29, 15 August 2024 by Busk (talk | contribs)
Jump to navigation Jump to search

Get inactive accounts

Import-Module ActiveDirectory
$ouPath = "OU=Some Accounts,DC=example,DC=com"
$usersNoPasswordReset = Get-ADUser -Filter {
    PasswordLastSet -gt "7/11/2023 00:00:00 AM" -and
    LastLogonDate -lt "7/11/2023 00:00:00 AM" -and
    SamAccountName -like "somesvc-*" -and
    Enabled -eq $true
} -SearchBase $ouPath -Properties PasswordLastSet, LastLogonDate, Enabled |
    Select-Object Name, SamAccountName, PasswordLastSet, LastLogonDate, Enabled
$usersNoPasswordReset | Format-Table -AutoSize