Skip to content

Instantly share code, notes, and snippets.

@jeremytbrun
Last active March 11, 2019 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremytbrun/f49a6085497ce019814b9d8a9d83410c to your computer and use it in GitHub Desktop.
Save jeremytbrun/f49a6085497ce019814b9d8a9d83410c to your computer and use it in GitHub Desktop.
Get-ADUserWhenDisabled
$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