Greg Altman

IT Leader, Writer, Speaker

Menu
  • Home
  • Speaking
  • About Me
  • Reviews
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

Category: PowerShell

Categories

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

© 2025 Greg Altman | Powered by Minimalist Blog WordPress Theme
%d