Here's the code:
# Michael L. Kelley Jr.
# March 15, 2017
# InactiveComputers.ps1
# A script to find inactive computers via days not logged on
$DaysInactive = 90
$time = (Get-Date).Adddays(-($DaysInactive))
Get-ADComputer -Filter {lastlogontimestamp -lt $time} -Properties Name.OperatingSystem , lastlogintimestamp| Select Name.OperatingSystem,
@{N='lastlogontimestamp'; E={[DateTime]::FromFileTime($_. lastlogontimestamp)}}
Read-Host -Prompt "Press enter to exit"
Running this script on your AD server, will check for computers that haven't been logged on for 90 days or more. It will return the AD computer name, operating system, and time last logged on. Perfect for cleaning up active directory for systems that are no longer around. Just change the $DaysInactive variable as needed.
No comments:
Post a Comment