Need to restart all the Windows computers on the network? This script reads a text file populated with computer names and performs the remote remote restart on them. I use this all the time to forcibly restart computers that are still logged on – but in distant locations on the network – when performing system maintenance and software upgrades outside of office hours.
‘ ***************************************************************
‘ * Script to Restart Network Computers
‘ * based on computers names list in a file.
‘ * This script checks computer’s availability first via WMI ping
‘ * Ceyhun Kirmizitas
‘ ***************************************************************
On Error Resume Next
Dim strComputer
Dim objShell, objExec, strCmd, strTemp
Set fso = CreateObject("Scripting.FileSystemObject")
Set objInputFile = fso.OpenTextFile("Dclist.txt",1,True)
Do While objInputFile.AtEndOfLine <> True
strComputer = objInputFile.ReadLine
WScript.Echo strComputer & " trying to contact with specified host"
If PingComputer2() Then
WScript.Echo strComputer & " contacted with host"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
objOperatingSystem.Reboot()
Next
WScript.Echo strComputer & " Now Restarting host"
Else
WScript.Echo strComputer & " could not contacted with specified host. We will try to contact with the next host"
End If
WScript.Echo "——————————————————— "
Loop
‘Function PingComputer()
‘ strCmd = "ping -n 1 " & strComputer
‘ Set objShell = CreateObject("WScript.Shell")
‘ Set objExec = objShell.Exec(strCmd)
‘ strTemp = UCase(objExec.StdOut.ReadAll)
‘ If InStr(strTemp, "REPLY FROM") Then
‘ PingComputer = True
‘ Else
‘ PingComputer = False
‘ End If
‘End Function
‘==========================================================================
‘ The following function will test if a machine is reachable via a ping
‘ using WMI and the Win32_PingStatus Class
‘==========================================================================
Function PingComputer2()
Dim wmiQuery, objWMIService, objPing, objStatus
wmiQuery = "Select * From Win32_PingStatus Where Address = ‘" & strComputer & "’"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objPing = objWMIService.ExecQuery(wmiQuery)
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) Or objStatus.Statuscode<>0 Then
PingComputer2 = False ‘if computer is unreacable, return false
Else
PingComputer2 = True ‘if computer is reachable, return true
End If
Next
End Function

Cloud and infrastructure professional with nearly two decades of experience in enterprise IT environments, spanning public cloud, private cloud, and hybrid architectures.