To Specify inactivity range value below :
Command
:
$DaysInactive = 180 [Enter]
To $time variable converts $DaysInactive to LastLogonTimeStamp property format for the -Filter
Command
:
$time = (Get-Date).Adddays(-($DaysInactive)) [Enter]
To Identify and collect inactive computer accounts:
Command
:
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize
$null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName, LastLogonDate| Export-CSV “C:\Temp\StaleComps.CSV” –NoTypeInformation [Enter]
Example as below :
And the
result, will get in csv file.
ALKNETWORK