find the computer user last login

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
cymba
Posts: 23
Last visit: Thu Jan 27, 2011 7:23 am

find the computer user last login

Post by cymba »

Hi Jay,

wonder if you can help me?
I have a list of users I want to find the last time they logged in and the computer that was login to. i wonder if you have a powershell script that facilitate this?

Thanks in advance.

User avatar
cymba
Posts: 23
Last visit: Thu Jan 27, 2011 7:23 am

find the computer user last login

Post by cymba »

Hi Jay,

wonder if you can help me?
I have a list of users I want to find the last time they logged in and the computer that was login to. i wonder if you have a powershell script that facilitate this?

Thanks in advance.

jvierra
Posts: 14890
Last visit: Tue Aug 03, 2021 6:22 am
Answers: 12
Has voted: 3 times
Been upvoted: 10 times

find the computer user last login

Post by jvierra »

In a domain the last logn time is held on the domain controllers. Just how toretrieve this depends on the level of the domain.

To find the machine lofgged into you would need to scan the Event log of the DC to find the login event then parse the record to obtain the machine name. This is also subject to domain configuration.

With Vista and later we can use Get-WinEvent. WIth earlier OS versions WMI is probably the best approach.

Look in the script sharing section for examples of reading the event log.



Locked