PowerShell - List Stale Workstations in AD, Currently set to -120 days
- Jon Boyette
- Jan 7, 2022
- 1 min read
Set as desired, searches the Workstations and add domain for OU. Outouts to c:\temp\workstationsstale120days - date.csv. This tests the computer object or Get-ADComputer passwordlastset. This shows the object not logged into the - days defined.
Import-Module ActiveDirectory
$date = [DateTime]::Today.AddDays(-120)
Get-ADComputer -Filter ‘PasswordLastSet -le $date’ -SearchBase "OU=workstations,dc=domain,dc=com" -properties PasswordLastSet | Export-Csv -path C:\temp\WorkstationsStale120days_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation
Comments