Created
April 9, 2018 11:29
-
-
Save conrjac/bc26a8d7f38b5e302b007153a4a2c9d3 to your computer and use it in GitHub Desktop.
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
import-module activedirectory | |
$DaysInactive = 90 | |
$time = (Get-Date).Adddays(-($DaysInactive)) | |
# Get all AD computers with lastLogonTimestamp less than our time | |
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time -and OperatingSystem -notlike "*server*"} -Properties LastLogonTimeStamp,OperatingSystem | | |
# Output hostname and lastLogonTimestamp into CSV | |
select-object Name | export-csv C:\OLD_Computers.csv -notypeinformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment