Last active
May 22, 2017 11:25
-
-
Save tech-zombie/4a35d95f5dd64187eca6f40ac4919fa1 to your computer and use it in GitHub Desktop.
polls ad for computer objects that have not called home for a period of time, can either report or delete them.
This file contains 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
import-module activedirectory | |
#finddomain or enter manually | |
#$domain = (Get-WmiObject Win32_ComputerSystem).Domain | |
#domain = my.domain.com | |
#edit for number of days to go back | |
$DaysInactive = 90 | |
$time = (Get-Date).Adddays(-($DaysInactive)) | |
# Get all AD computers with lastLogonTimestamp less than our time | |
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp | | |
# Output hostname and lastLogonTimestamp into CSV | |
#select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv OLD_Computer.csv -notypeinformation | |
#delete AD objects | |
#remove-adcomputer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment