Created
December 4, 2017 14:37
-
-
Save julian-alarcon/f60d7e33fd286d64a82b983c894d783d to your computer and use it in GitHub Desktop.
PowerShell script to get and remove old computers not connected to AD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Script to regenerate list and remove old computers not logged to Domain Controller in 2 Months | |
$time = (Get-Date).AddMonths(-2) | |
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties * | select name, distinguishedname,LastLogonDate| export-csv computers_2m.txt | |
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties distinguishedname| Remove-ADObject -Recursive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment