WhoKilledKenny
MIS
Issue: Same user shows up logged on each workstation. The script I am using should read a list of Workstation names and report who is logged on the PC. Problem is when running the script the first username shows for all PC. I must be missing something in the code.
Example of output:
UserName: domain\JSmith is logged in at computer wkr01
UserName: domain\JSmith is logged in at computer wkr10
UserName: domain\JSmith is logged in at computer wkr35
UserName: domain\JSmith is logged in at computer wkr02
UserName: domain\JSmith is logged in at computer wkr17
Code:
On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\Scripts\WorkStations.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, VbCrLf)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "UserName: " & objItem.UserName & " is logged in at computer " & strComputer
Next
Next
Example of output:
UserName: domain\JSmith is logged in at computer wkr01
UserName: domain\JSmith is logged in at computer wkr10
UserName: domain\JSmith is logged in at computer wkr35
UserName: domain\JSmith is logged in at computer wkr02
UserName: domain\JSmith is logged in at computer wkr17
Code:
On Error Resume Next
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
("c:\Scripts\WorkStations.txt", ForReading)
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText, VbCrLf)
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
Wscript.Echo "UserName: " & objItem.UserName & " is logged in at computer " & strComputer
Next
Next