Sometimes you have to identify the last logon of a user or computer object in Active Directory. With this little code, you can list all users/computers ordered from old to new logins.

Get-ADComputer -Filter * -SearchBase "OU=<OU>,DC=<DC>,DC=DC=<DC>" -Server "Domain Controller" -Properties Lastlogon,LastLogonTimestamp | 
Sort-Object LastLogonTimeStamp | Select-Object Name,LastLogonTimeStamp,@{Name="LastLogonDate";Expression={$([datetime]::FromFileTime($_.LastLogonTimestamp))}​}

Have fun

Leave a Reply

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