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.

 

1 Comment

Leave a Reply