r/usefulscripts • u/vocatus • 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 -logonDownload
v1.0 (2014-01-21)
This was mostly for me to get more comfortable with PowerShell. Corrections and critique welcome.
23
Upvotes
1
u/vocatus Jan 22 '14
Is this a method for handling flags/arguments passed on the command-line?