Ping Multiple Computers Until They're Up

Friday, June 22, 2007
Here's a short VBScript I wrote that I used for an Windows 2003 R2 implementation last night. It quickly pings a group of computers in rapid succession.

First, create a list of computers using Notepad and save it to a file named Computer.lst. Next, copy the script below to the same folder.

The script will loop through the list of computers, pinging each one with a small packet and tell you whether it's up or down. The script will loop continuously through the list until all computers are up.

Set ws = WScript.CreateObject("WScript.Shell")
Set fs = CreateObject("Scripting.FileSystemObject")

Do
    downComputers = 0
    Set f = fs.OpenTextFile("Computer.lst", 1, True)
    Do While NOT f.AtEndOfStream
    compName = f.ReadLine
    If ws.Run("ping -n 1 -l 1 " & compName, 0, True) = 0 Then
       WScript.Echo compName & " is UP"
    Else
       WScript.Echo compName & " is DOWN"
       downComputers = downComputers + 1
    End If
    Loop
    f.Close
    WScript.Echo "Unreachable computers: " & downComputers
    WScript.Echo
Loop Until downComputers = 0


This works well when you have a group of computers all rebooting at the same time. One of these days I'll recode this into an HTM application with pretty green and red lights.

No comments:

Post a Comment

Thank you for your comment! It is my hope that you find the information here useful. Let others know if this post helped you out, or if you have a comment or further information.