WMI scripting template that runs the script against a list of computer found in a comma-separated-values file named C:\Scripts\Computers.txt. Individual computer names within the text file should be separated by commas, with no spaces between the commas and the computer names. For example: atl-ws-01,atl-ws-02,atl-ws-03. This script pings the relevant computer before trying to make a connection.

Visual Basic
Edit|Remove
On Error Resume Next

Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\scripts\computers.txt", ForReading)

Do Until objTextFile.AtEndOfStream 
    strComputers = objTextFile.ReadAll
Loop

objTextFile.Close

arrComputers = Split(strComputers, ",")

For Each strComputer in arrComputers

    Set objShell = CreateObject("WScript.Shell")
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)

    Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then

            ' =====================================================================
            ' Insert your code here
            ' =====================================================================

            Set objWMIService = GetObject _
                ("winmgmts:\\" & strComputer & "\root\cimv2")
            Set colItems = objWMIService.ExecQuery _
                ("Select * From Win32_OperatingSystem")
            For Each objItem in ColItems
                Wscript.Echo strComputer & ": " & objItem.Caption
            Next

            ' =====================================================================
            ' End
            ' =====================================================================

        Else
            Wscript.Echo strComputer & " could not be reached."
        End If
    Loop
Next