WMI 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 each computer. 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
On Error Resume Next

Const WbemAuthenticationLevelPktPrivacy = 6

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

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

If strCredentials = "" Then
End If

arrCredentials = Split(strCredentials," ")
strUser = arrCredentials(0)
strPassword = arrCredentials(1)
strNamespace = "root\cimv2"

For Each strComputer in Wscript.Arguments

    Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
    Set objWMIService = objwbemLocator.ConnectServer _
        (strComputer, strNamespace, strUser, strPassword)
    objWMIService.Security_.authenticationLevel = WbemAuthenticationLevelPktPrivacy

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

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

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