Skip to content

Instantly share code, notes, and snippets.

@conrjac
Created April 9, 2018 11:29
Show Gist options
  • Save conrjac/bc26a8d7f38b5e302b007153a4a2c9d3 to your computer and use it in GitHub Desktop.
Save conrjac/bc26a8d7f38b5e302b007153a4a2c9d3 to your computer and use it in GitHub Desktop.
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