Skip to content

Greg Altman

Solutions, Learnings, PowerShell, and random thoughts.

Menu
  • Home
  • Tech Reviews
  • Github Repos
  • About Me
Menu

Powershell Tuesday Quick Tip #2

Posted on March 13, 2018 by Greg Altman

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!

Share this:

  • Click to share on Bluesky (Opens in new window) Bluesky
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

Disclaimer: The thoughts, ideas and code on this blog are my own and do not represent any employer, past or present. All code is for demonstration and educational purposes only. Use at your own risk

Categories

  • Ad-hoc and Random
  • Blog
  • Career
  • Cloud
  • Events
  • PowerShell
  • Reviews
  • Security
  • Server Stuff
  • Troubleshooting
  • Uncategorized

Overall Rating
0.0
© 2026 Greg Altman | Powered by Minimalist Blog WordPress Theme
%d