PowerShell: Check computer last logon date

In a recently closed ticket, I had specified that the solution would be automatically applied upon reboot of a computer. As so often happens one of the twenty or so users affected by the solution emailed to say that it didn’t work. Having dealt with said user before, I had a hunch that they hadn’t actually read the solution text, and wanted to see if I could find out when the computer had last been rebooted.

Predictably (particularly assuming you’ve read the title of this post), PowerShell has an applet for that. This time, we’re looking at the Get-ADComputer applet. By specifying the computer object using the Identity parameter, and getting all properties using the Properties parameter, we get a dump of all the properties for the AD computer object, much the same as we did when retrieving properties for a user object.

The complete query looks like this: Get-ADComputer -Identity %COMPUTER% -Properties *. By looking through the output for the LastLogonDate, we can quickly identify when a user last logged on to the computer. Other useful properties are AccountExpirationDate, Created, telling us when the computer object was added to AD, and Enabled, which – if set to False – tells us that login is impossible.

I recommend running the command against a machine and poking around to see if you can find other properties that are useful to you.


Posted

in

by

Comments

By posting a comment, you consent to our collecting the information you enter. See privacy policy for more information.

This site uses Akismet to reduce spam. Learn how your comment data is processed.