none
Powershell - Show last user logon time RRS feed

  • Question

  • I need to query a list of computers for what user last logged in, and when. I found this:

    https://blogs.technet.microsoft.com/heyscriptingguy/2012/02/19/use-powershell-to-find-last-logon-tim...

    It's a great script, but one issue I am having I'm hoping someone can help with. 

    The majority of machines I ran this against shows the current time script was ran under the time column. I am running against several hundred computers and there's about 18 per minute the script gets too but stamps the time as the time script is run. Example:

    6/27/2017 8:34
    6/27/2017 8:34
    6/27/2017 8:34
    6/27/2017 8:35
    6/27/2017 8:35
    6/27/2017 8:35
    6/27/2017 8:35

    If I log in to one of the PCs there is no user logged in. Any ideas? Or does anyone have another script to check? I found plenty for querying AD but I need to query each computer for logons on that computer. 




    • Edited by commdudeaf Tuesday, June 27, 2017 1:17 PM
    • Moved by Bill_Stewart Wednesday, July 26, 2017 7:49 PM This is not "fix/debug/rewrite script I found on the Internet" forum
    Tuesday, June 27, 2017 1:15 PM

All replies

  • Sorry but we do not fix scripts found on the Internet. 

    The script you have referenced is just an example of how you might write a script.  You can change it to report the time in any way you like.

    Please post to the author of the script here: https://gallery.technet.microsoft.com/scriptcenter/Get-LastLogon-Determining-283f98ae/view/Discussions#content


    \_(ツ)_/

    Tuesday, June 27, 2017 1:31 PM
  • Thanks JRV, I did post to the author earlier. I am hoping someone may have a suggestion for another script to try at least. 

    Tuesday, June 27, 2017 1:59 PM
  • The script you posted will not work as required on any current version of Windows.  It was written 5 years ago for XP and WS2003.  Reading the profile with WMI always updates the time in current versions.

    To get last logon you need to access the Event log and find the last logon/logoff records.   It is actually much easier to do.  There are examples in the Gallery.


    \_(ツ)_/

    Tuesday, June 27, 2017 2:03 PM