Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

Get the last user logged in (Powershell)

*** THIS SCRIPT IS PROVIDED WITHOUT WARRANTY, USE AT YOUR OWN RISK ***

This script connects to the c$ admin share using the Get-ChildItem cmdlet and looks at the LastWriteTime value of the user profile folder in the C:\users in order to determine who logged in last to the machine. The script collects the Computer name, Username and the LastWriteTime of the users’ profile.

This is not the most elegant way to do it but it seems to work since Microsoft has no built-in method to get the last user that logged in to a particular machine.

 

Leave a Reply

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