PowerShell - List all Stale Computers in AD, Set at 90 days currently
- Jon Boyette
- Jan 7, 2022
- 1 min read
Can tweak the days however needed, change the -90, to a -120, -30, -60 etc, and the output is the servers that have been stale that long in AD, By using the Computer Object, and when the computer password last set, or logged in. This is searching from a defined OU
Import-Module ActiveDirectory
$date = [DateTime]::Today.AddDays(-90)
Get-ADComputer -Filter ‘PasswordLastSet -le $date’ -SearchBase "OU=servers,dc=DOMAIN,dc=COM" -properties PasswordLastSet | Export-Csv -path C:\temp\ServersStale90days_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation
Comments