Here is a VBScript that will do what your asking, I just threw it together but it works great.
How to use it:
1. Copy the code below into notepad (with word wrap disabled).
2. save it as any name with the .vbs extention. Eg. LoggedOnUsers.vbs
2. Create a text file on the root of your C: drive called Computers.txt
3. In the Computers.txt file, enter the name of each machine you wish to check. One machine per-line as the script uses this text file to create an array. The array is delimited by a carriage return, so it Should look like the following:
ComputerName1
ComputerName2
ComputerName3
and so on...
4. you can place the script where ever you like, for this example it is on the root to C:
5. Open a commmand promt and type the following command:
c:\cscript LoggedOnUsers.vbs > LoggedOnUsers.txt
This command runs the script and send the output to the LoggedOnUsers.txt file, this is where you will find the results.
Results will look similar to the following:
UserName: Domain\Username is logged in at computer ComputerName1
===========================================================================
ComputerName2, The remote server machine does not exist or is unavailable
===========================================================================
No User is logged on system: ComputerName3
===========================================================================
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\Computers.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, VbCrLf)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err <> 0 Then
WScript.Echo strComputer & ", " & Err.Description
WScript.Echo "==========================================================================="
Err.Clear
Else
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
If objItem.Username <> "" Then
WScript.Echo "UserName: " & objItem.UserName & " is logged in at computer " & strComputer
WScript.Echo "==========================================================================="
Else
WScript.Echo "No User is logged on system: " & strcomputer
WScript.Echo "==========================================================================="
End If
Next
End If
Set objItem = Nothing: Set colItems = Nothing:
Set objWMIService = Nothing
Next