How to Find Inactive Computers in Active Directory using PowerShell

1 Min Read

How to Find Inactive Computers in Active Directory using PowerShell.

To identify inactive computer accounts, you will always target those that have not logged on to Active Directory in the last 90 days. To accomplish this goal, you need to target the LastLogonTimeStamp property and then specify a condition with the time as shown in the following PowerShell commands:

$DaysInactive = 90

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

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

If you wish to search computer accounts that have been inactive for more than 90 days, all you need to do is modify the $DaysInActive variable value. The current value is set at 90 days; however, you can specify your own value.

To export output to a CSV file, add the Export-CSV PowerShell cmdlet as shown in the following command:

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version