This week is an easy one. Cleaning up Active Directory of old computers. Sometimes a machine gets retired or just completely craters and in the haste to get the user back up and going…. some clean up is forgotten. Easy to fix. this little snippet returns the time since PC has logged into the domain in DDD.HH:MM:SS format
[code lang=’powershell’]
$timespan = ‘90.00:00:00′
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan $timespan|
Foreach-Object {Write-output $_.name} [/code]
Of course it’s easy to add
[code lang=’powershell’] |Export-csv -Path C:\OLDPC.csv
[/code]
to the pipeline which gives you a CSV file to review and feed into a “Delete-OldComputer” oneliner!
See ya next week!
Category: PowerShell