ADSI scripting template that runs the script against each computer whose name was entered as a command-line argument (individual computer names must be separated by blank spaces). This script prompts you to enter a user name and password to be used when connecting to the remote computers. To run the script, type the script name followed by the names of the computers you want to run the script against. For example: my_script.vbs atl-ws-01 atl-ws-2 atl-ws-03.

Visual Basic
Edit|Remove
On Error Resume Next

Const ADS_SECURE_AUTHENTICATION = 1
Const ADS_USE_ENCRYPTION = 2

If Wscript.Arguments.Count = 0 Then
    Wscript.Echo "You must enter at least one computer name when starting this script."
    Wscript.Quit
End If

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)

For Each strComputer in Wscript.Arguments

    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
    ' =====================================================================

Next