Most of this script comes from AdamTheAutomator’s website, but I did make some improvements for my own needs that included a custom class and some adjustments to the PowerShell object. I have plans to modify this further so I can use it for larger automation activities.
“Query User” is the perfect tool for administering multi-user systems when you want to see who is currently logged into a system. Open command prompt and type in the command. This command also works even at home when you are the only user of a computer.