How can I detect if a user has logged on or off from a windows system (preferably that works with win7, vista or XP) using powershell?
I want to register the date and time of each logging on and off of the machine.
Thank you in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can get this infromation from the event log:
Logons have an InstanceId of 7001, logoffs have 7002. The user account is a SID in ReplacementStrings.
Here is some more useful code for you.
You can also get these events from a remote computer by adding the “-ComputerName” parameter to Get-EventLog.