Skip to content

Instantly share code, notes, and snippets.

@nopslider
Last active September 15, 2016 19:24
Show Gist options
  • Save nopslider/b23fba2b4f4a310e2cff to your computer and use it in GitHub Desktop.
Save nopslider/b23fba2b4f4a310e2cff to your computer and use it in GitHub Desktop.
Find enabled and non-locked stale AD accounts (accounts which haven't logged in for over X months. Also lists accounts which have never logged in)
Get-ADUser -Filter * -Properties * `
| where {($_.enabled -eq $true) -and ($_.lockedout -eq $false)} `
| where {$_.lastlogondate -lt (Get-Date).AddMonths(-3)} `
| select SamAccountName, lastlogondate `
| sort lastlogondate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment