LastLogonTimestamp

Written by Arne Tiedemann on Monday June 18, 2018

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))}}