There is an easy and quick way to get .TXT file with all AD computer names and relativse last logon dates.
- You must execute Powershell module with Administrative rights.
- Import-Module activedirectory
- Get-Help Get-ADComputer
- Get-ADComputer -Filter * -Properties * | Sort LastLogonDate | FT Name, LastLogonDate -Autosize | Out-File C:\Temp\ComputerLastLogonDate.txt
Alternative approach could be:
- $DaysInactive = 90
- $time = (Get-Date).Adddays(-($DaysInactive))
- Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName
- Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -ResultPageSize 2000 -resultSetSize $null -Properties Name, OperatingSystem, SamAccountName, DistinguishedName | Export-CSV “C:\Temp\StaleComps.CSV” –NoTypeInformation
[original articles]