Import-Module activedirectory
Get the list of computers whose last password set in the network from TODAY to next 3 years. (look -ge switch)
$old = (Get-Date).AddDays(-1095) Get-ADComputer -Filter 'PasswordLastSet -ge $old' -Properties * | Sort PasswordLastSet | FT Name,PasswordLastSet,LastLogonDate,IPv4Address -Autosize
Get the list of computers whose last password set in the network for 4 years back. (look -lt switch)
$old = (Get-Date).AddDays(-1460) Get-ADComputer -Filter 'PasswordLastSet -lt $old' -Properties * | Sort PasswordLastSet | FT Name,PasswordLastSet,LastLogonDate,IPv4Address -A Get-ADComputer -Filter 'Name -like "IT-*"' -Properties * | Sort PasswordLastSet | FT Name,PasswordLastSet,LastLogonDate,IPv4Address -Wrap -Auto | Out-File C:\Temp\ComputerLastLogonDate.txt
References:
http://woshub.com/get-adcomputer-getting-active-directory-computers-info-via-powershell/
http://www.powershelladmin.com/wiki/Getting_computer_names_from_AD_using_Powershell
https://blogs.technet.microsoft.com/askds/2010/02/04/inventorying-computers-with-ad-powershell/