Get a list of old computers using Powershell

Hi guys, just a short posting here.

If you want to get a list of computer that haven’t logged in to the domain in the past X days use the following to commands:

 

$Date = [DateTime]::Today.AddDays(-X)

Get-ADComputer -Filter ‘LastLogonDate -le $Date’ -Properties LastLogonDate | FT Name,LastLogonDate

 

Just change the X to the number of days you want to display.

For instance, to display all computers that haven’t logged in in the past 90 days:

 

$Date = [DateTime]::Today.AddDays(-90)

Get-ADComputer -Filter ‘LastLogonDate -le $Date’ -Properties LastLogonDate | FT Name,LastLogonDate

 

You can also use this command to display all computers that haven’t changed their password in the past X days, for this just change the last command:

 

Get-ADComputer -Filter ‘PasswordLastSet -le $Date’ -Properties PasswordLastSet | FT Name,PasswordLastSet

What do you think about this post?