I'd like to have an email notification on user logon to certain machines. It's a domain environment so username would be a nice to have in the email. I can create a logon triggered scheduled task to run a script but not sure how to get the script to figure out what user logged on since $env:username would give me the user account that runs the task.
I would also choose the eventlog path.. Since your only interested in "some" clients, I would setup Windows Event Forwarding Service and create a policy for the clients in question.. then you can run the script from a centralized location..
Tried to do "Switch account" and then get username from Win32_ComputerSystem. Looks like it return only one currently logged in user. Info from MSDN:
Data type: string
Access type: Read-only
Qualifiers: MappingStrings ("Win32API|System Information Functions|GetUserName")
Name of a user that is logged on currently. This property must have a value. In a terminal services session, UserName returns the name of the user that is logged on to the console—not the user logged on during the terminal service session.