Skip to main content

Inactive Computers

$DaysInactive = 365 

$time = (Get-Date).Adddays(-($DaysInactive)) 

 

 

Print on Screen: 

 

Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName 

 

 

Export: 

 

Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName | Export-CSV “C:\accent\StaleComps.CSV” –NoTypeInformation 

 

 

Only Enabled: 

 

Get-ADComputer -Filter {(LastLogonTimeStamp -lt $time) -and (Enabled -eq $True)} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName | Export-CSV “C:\accent\StaleComps.CSV” –NoTypeInformation