ADSI scripting template that runs the script against all the computers listed in an Excel spreadsheet named C:\Scripts\Servers.xls. The computer names should be listed in column A of the spreadsheet, one computer per row, and with no blank cells cells between rows. This script pings the relevant computer before trying to make a connection.

Visual Basic
Edit|Remove
On Error Resume Next

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\servers.xls")
x = 1

Do Until objExcel.Cells(x, 1).Value = ""
    If objExcel.Cells(x, 1).Value = "" Then
        Exit Do
    End If

    strComputer = objExcel.Cells(x, 1).Value 

    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
    x = x + 1
Loop

objWorkbook.Close
objExcel.Quit