Last active
March 11, 2019 14:35
-
-
Save jeremytbrun/f49a6085497ce019814b9d8a9d83410c to your computer and use it in GitHub Desktop.
Get-ADUserWhenDisabled
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Server = "SERVER" # This is your target domain controller | |
Get-ADUser -Filter "enabled -eq `$false" -Server $Server -Properties sAMAccountName, givenName, sn, userAccountControl, mail, employeeID, lastLogonDate | ForEach-Object { | |
$AttrRepMeta = Get-ADReplicationAttributeMetadata -Object $_ -Properties userAccountControl -Server $Server | |
$_ | Add-Member NoteProperty "whenDisabled" $AttrRepMeta.LastOriginatingChangeTime -Force | |
Write-Output $_ | |
} | Where-Object {$_.whenDisabled -ge [DateTime]::Now.AddMonths(-1)} | Select-Object sAMAccountName, givenName, sn, userAccountControl, mail, employeeID, lastLogonDate, whenDisabled | Export-Csv C:\Temp\DisabledUsers.csv -NoTypeInformation -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment