ADSI 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 each remote 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 objComputer = GetObject("WinNT://" & strComputer & "")
            objComputer.Filter = Array("User")
            For Each objUser in objComputer
                Wscript.Echo objUser.Name
            Next

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

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