Windows administrators often experience situation to find & validate active logged in user session of bulk remote computers before performing administrative tasks and there are many ways to fetch the details, one of the time saving way is to find it out using powershell script.
Here in this article we have used a simple single line powershell script that serve our needs.
Powershell script to fetch logged in user details:
We use “win32_computersystem” WMI class instance to fetch attributes of windows computer by using along with get-wmiobject.
get-wmiobject -class Win32_computersystem | select username
The above command will fetch the active logged in user session details of local computer, whereas we need to modify and include few other parameters in order to fetch the logged in user session details of remote computer.
The below script uses string called computername where we specify name of the computer to which the command needs to be executed.
get-wmiobject -class Win32_computersystem -computername nameofcomputer | select username
We even can alter the above code as below to find logged in user session details of bulk remote computer.
get-wmiobject -class Win32_computersystem -computername $machines | select name,username
We used get-content cmdlet to fetch bulk remote computer name or IP address details for execution and using it along with our old script to serve our needs.
Make sure that you have all required administrative access before executing this script
This script is working and tested on the following below mentioned operating systems
Windows 7,Windows 8, Windows 10, Windows Server 2012 R2, Windows Server 2016
Please feel free to share your thoughts and queries in the comment session below and do follow us on facebook and twitter page to find more similar articles.