This code will open a file and read it a line at a time, storing the current line in a variable called strComputer
. You will need to put your rebooting code inside this loop...or, better yet, turn your code into a function that accepts a computer name to reboot.
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "computers.txt"
Set objFile = objFS.GetFile(strFile)
Set ts = objFile.OpenAsTextStream(1, -2)
Do Until ts.AtEndOfStream
strComputer = ts.ReadLine
' ----
' your code to reboot goes here
' ---
Loop
ts.Close
EDIT
I added your code...this works for me.
Dim objShell
Dim fso, file
Dim objWMIService, objComputer, colComputer
Dim strLogonUser, strLogonUser1, strComputer
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "ComputerList.txt"
Set objFile = objFS.GetFile(strFile)
Set ts = objFile.OpenAsTextStream(1, -2)
Do Until ts.AtEndOfStream
strComputer = ts.ReadLine
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
If (IsNull(objComputer.UserName)) Then
objShell.Run "psshutdown \\" & strComputer & " -r -c -t 120"
WScript.Echo "No users logged on at " & strComputer & ". Computer restarted."
WScript.Quit
Else
strLogonUser = Split(objComputer.UserName,"\")
strLogonUser(1) = UCase(Left(strLogonUser(1),1)) & Trim(Mid(strLogonUser(1),2,20))
Wscript.Echo strLogonUser(1) & " is logged on at " & strComputer
End If
Next
Loop
ts.Close