PowerShell – Find the name and time of the last logged on user

This one goes on the category of crazy-oneliners.
After I finished writing it I looked back and saw just how crazy huge it was…
Nevertheless, I still like to share:

7 comments

  1. Michel de Rooij says:

    That’s not huge, that’s a puppy. But nevertheless, that verbose format will help the unenlightened read and understand it.

  2. MARS822 says:

    Nice. Need to purge an app cache in a regular basis and this is perfect for narrowing it to the regular user. Thanks!

    BTW – Michel de Rooij is clearly a douche.

  3. Jeff Wouters says:

    Hi Mars,
    Happy I could help.
    Please, don’t call people names. If they want to express their opinion then let them.
    If they really are acting like a douche, there is always a little thing called karma.
    Like Sun Tsu wrote: If you wait by the river long enough, the bodies of your enemies will float by…
    Jeff.

  4. Harold says:

    Jeff, you too are a douche for the last comment.

  5. Abdu; says:

    I want to count the number of times user logged in to a desktop machine using his/her domain credentials, anyway to do this using same powershell script ?

    when i use few powershell scripts its fetching the total login count from AD server , but i want to count number of times each domain user logged into Desktop machine say MACHINE1 and two users Mark and Tom

  6. Erez says:

    Wow this is just what I was looking for!
    I spent the past couple of days figuring out how to get the last logged on user. I got it working by querying the System event log (Get-WinEvent) and it worked for my purpose but this helped me get the correct result every time – thank you!

Leave a Reply

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