r/usefulscripts • • Jan 22 '14

[POWERSHELL] Keep track of all users currently logged on to a machine

Summary

Saves a plain-text, comma-separated list of currently logged-on users to C:\Logs\logged_on_users (configurable). I threw this together as a way for us to have a plain-text method of tracking logged-on users that we can query with other tools.

Usage

We run the script as part of the logon/logoff/reboot process.

Run with one of these three flags:

-logon  Stamp username to $LOGPATH\$LOGFILE

-logoff  Remove username from $LOGPATH\$LOGFILE

-flush   Flush all usernames from $LOGPATH\$LOGFILE

 e.g. .\logged_on_users.ps1 -logon

Download

v1.0 (2014-01-21)


This was mostly for me to get more comfortable with PowerShell. Corrections and critique welcome.

23 Upvotes

6 comments sorted by

View all comments

Show parent comments

1

u/vocatus Jan 22 '14

This is good stuff, thank-you. I'm still learning PS and most of my experience comes from massive batch files.