ADSI scripting template that runs the script against a list of computers found in a text file named C:\Scripts\Servers.txt. In the text file, computer names should be listed one computer per line. This script prompts you to enter a user name and password to be used when connecting to the remote computers.

Visual Basic
Edit|Remove
On Error Resume Next

Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_USE_ENCRYPTION = 2

strCredentials = InputBox _
    ("Please enter the user name, a blank space, and then the password:", _
        "Enter User Credentials")

If strCredentials = "" Then
    Wscript.Quit
End If

arrCredentials = Split(strCredentials," ")
strUser = arrCredentials(0)
strPassword = arrCredentials(1)

Const ForReading = 1

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

Do Until objTextFile.AtEndOfStream 
    strComputer = objTextFile.Readline

    strComputer = "WinNT://" & strComputer

    Set objDSO = GetObject("WinNT:")
    Set objComputer = objDSO.OpenDSObject _
        (strComputer, strUser, strPassword, _
            ADS_SECURE_AUTHENTICATION AND ADS_USE_ENCRYPTION)

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

    objComputer.Filter = Array("User")
    For Each objUser in objComputer
        Wscript.Echo objUser.Name
    Next

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

Loop

objTextFile.Close