Parses an input file and uses the data to automatically populate ADS with the correct compute node information, including node names and MAC address values. These values are later used by Sysprep.exe to configure the node images during deployment. This script contributed by Markus Christen of Microsoft.

Visual Basic
Edit|Remove
'----------------------------------------------------------------------------
' ADS Installation Script HPC
' Purpose: Adding ADS Devices for HPC installation
' Version: 3.6
' Data     : 21.03.06
' Owner: Markus Christen / MCS Brazil
'----------------------------------------------------------------------------
Option Explicit
Err.Clear
On error resume next

Dim objSvc              
Dim objDev              
Dim objDevInst          
Dim objDevhwaddr        
Dim objDevhwaddrInst    
Dim objDevvar           
Dim objDevvarInst       
Dim varSrvName, varSrvDescription, varSrvMAC, varSrvImageName, varHPCClusterName
Dim varAdminpassword, varDomain, varDomainPassword, varDomainUsername
Dim varMachineName,varMachineOU 
Dim varProductKey
Dim varPublicIP, varPublicSubNet, varPublicGateway, varPublicDNS, varPublicNicName, varPublicMAC
Dim varPrivateIP, varPrivateSubNet, varPrivateGateway, varPrivateDNS, varPrivateNicName, varPrivateMAC
Dim varMPIIP,varMPISubNet,varMPIGateway,varMPIDNS,varMPINicName,varMPIMAC
Dim varNetworkTopology,varPartitionSize,varImageName
Dim oArgs, strText, x, strHelp
Dim objfso, objFile, stream, strObject, strLine, arrKey(5)
Dim varOrgName,VarFullName

'Get the command line args
set oArgs=wscript.arguments

'<<<<< Display Script Arguments Required >>>>>
strHelp="This script require the following arguments:"+VbCrLf+VbCrLf
strHelp=strHelp+"cscript HPCADS.vbs Devices.csv"+VbCrLf+VbCrLf

If oArgs.count=0 then 

wscript.echo strHelp 

ElseIf oArgs(0)="/?" then

wscript.echo strHelp

else

strText = oArgs.item(0)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strText, 1)

'Read licensing keys
x=0
while x <= 3

if not objFile.AtEndOfStream then
    strLine = Trim(objFile.ReadLine)
    strLine = GetNextToken(strLine, strObject)
    strLine = GetNextToken(strLine, strObject)    
    arrKey(x)=strObject
    x=x+1
end if
wend

varFullName =arrKey(0)
varOrgName=arrKey(1)
varProductKey = arrKey(2)

 
'Read each line and create device and user variables
while GetNextTarget(objFile) <> False
    Call SetDevice()
    wscript.echo varSrvName
    wscript.echo "...device created"
    Call SetVariables()
    wscript.echo "...user variables created"&vbcrlf
wend

objFile.Close

End if

'********************************************************
'*
'*  subroutine: GetNextTarget
'*  parameters: 
'*    stream        - file stream
'*    varAddress - IP Address
'*    strPort    - IP Port
'*    strHeader  - Host Header
'*  purpose:    Parse the steam and return the values from
'*        each column              
'*  returns:    none
'*
'********************************************************
function GetNextTarget(stream)
    dim strLine
    dim arStr
    dim n
    
    if not stream.AtEndOfStream then
        strLine = Trim(stream.ReadLine)
        strLine = GetNextToken(strLine, varSrvName)
        strLine = GetNextToken(strLine, varSrvDescription)
        strLine = GetNextToken(strLine, varSrvMAC)
        strLine = GetNextToken(strLine, varMachineName)
        strLine = GetNextToken(strLine, varAdminpassword)
        strLine = GetNextToken(strLine, varDomain)
        strLine = GetNextToken(strLine, varDomainUsername)
        strLine = GetNextToken(strLine, varDomainPassword)
        strLine = GetNextToken(strLine, varSrvImageName)
        strLine = GetNextToken(strLine, varHPCClusterName)
        strLine = GetNextToken(strLine, varNetworkTopology)
        strLine = GetNextToken(strLine, varPartitionSize)
        strLine = GetNextToken(strLine, varPublicIP)
        strLine = GetNextToken(strLine, varPublicSubNet)
        strLine = GetNextToken(strLine, varPublicGateway)
        strLine = GetNextToken(strLine, varPublicDNS)
        strLine = GetNextToken(strLine, varPublicNicName)
        strLine = GetNextToken(strLine, varPublicMac)        
        strLine = GetNextToken(strLine, varPrivateIP)
        strLine = GetNextToken(strLine, varPrivateSubNet)
        strLine = GetNextToken(strLine, varPrivateGateway)
        strLine = GetNextToken(strLine, varPrivateDNS)
        strLine = GetNextToken(strLine, varPrivateNicName)
        strLine = GetNextToken(strLine, varPrivateMac)
        strLine = GetNextToken(strLine, varMPIIP)
        strLine = GetNextToken(strLine, varMPISubNet)
        strLine = GetNextToken(strLine, varMPIGateway)
        strLine = GetNextToken(strLine, varMPIDNS)
        strLine = GetNextToken(strLine, varMPINicName)
        strLine = GetNextToken(strLine, varMPIMac)
        varMachineOu = Replace(strline, """", "") 'wlp - filter out extra quotes
        GetNextTarget = true
    else
        GetNextTarget = false
    end if
end function



'********************************************************
'*
'*  subroutine: GetNextToken
'*  parameters: 
'*    str -
'*    strToken - 
'*  purpose:    parse string to pull values
'*  returns:    value of each column
'*
'********************************************************
function GetNextToken(str, strToken)
    dim n
    dim a
    
    n = InStr(str, ",")
    If n =1 then wscript.quit    
    if n = 0 and a <> 1 then
      n = Len (str)
      strToken = Left(str, n)
      a= 1    
     wscript.echo "Token: " & strToken      
    else
      strToken = Left(str, n-1) 
    end if

    GetNextToken = Mid(str, n)

    while Left(GetNextToken, 1) = ","
            GetNextToken = Mid(GetNextToken, 2)
    wend
    

end function

'********************************************************************
'* Sub:     SetDevice
'*
'* Purpose: Create the device record
'*
'* Input:   None
'*
'* Output:  None
'*
'********************************************************************

Sub SetDevice()
On error resume next
' get root microsoft ads object
Set objSvc = GetObject("winmgmts:\\.\root\microsoftADS")
Call CheckForErrors("Failed: getobject root\microsoftads")
'wscript.echo varSrvName
' get devices object                    
Set objDev = objSvc.Get("Devices")
Call CheckForErrors("Failed: get Devices object")

' spawn device instance class                                                 
Set objDevInst = objDev.SpawnInstance_()
Call CheckForErrors("Failed: spawning Device instance object")

' set device properties 
     
objDevInst.Name = varSrvName
objDevInst.Description = varSrvDescription

' create device instance
objDevInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device")
                
' get device hwaddr object                                                                
Set objDevhwaddr = objSvc.Get("DeviceHWAddrs")
Call CheckForErrors("Failed: get DevicesHWAddrs object")

' create device hwaddr instance
Set objDevhwaddrInst = objDevhwaddr.SpawnInstance_()
Call CheckForErrors("Failed: spawning DeviceHwAddrs instance object")

' set device hwaddrs properties                
'wscript.echo varSrvName
objDevhwaddrInst.DeviceName = varSrvName
objDevhwaddrInst.type = 2
objDevhwaddrInst.hwaddr = varSrvMAC

' create device hwaddr instance                               
objDevhwaddrInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device hwaddr")

End Sub

'********************************************************************
'* Sub:     SetVariables
'*
'* Purpose: Set the device user variables
'*
'* Input:   None
'*
'* Output:  None
'*
'********************************************************************

Sub SetVariables()
On error resume next
' get device variables object
Set objDevvar = objSvc.Get("DeviceVariables")
Call CheckForErrors("Failed: get DevicesVariables object")

' create device variable instance
Set objDevvarInst = objDevvar.SpawnInstance_()
Call CheckForErrors("Failed: get DevicesVariable instance object")

' set device variable properties                                                         
objDevvarInst.DeviceName = varSrvName
objDevvarInst.Namespace = "user"

objDevvarInst.Name = "Adminpassword"
objDevvarInst.Value = varAdminpassword

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "Domain"
objDevvarInst.Value = varDomain

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "DomainPassword"
objDevvarInst.Value = varDomainPassword

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "DomainUsername"
objDevvarInst.Value = varDomainUsername

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "machinename"
objDevvarInst.Value = varMachineName

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "hpcclustername"
objDevvarInst.Value = varHPCClusterName

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "ProductKey"
objDevvarInst.Value = varProductKey

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "Imagename"
objDevvarInst.Value = varSrvImageName

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "MachineOU"
objDevvarInst.Value = varMachineOU

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "NetworkTopology"
objDevvarInst.Value = varNetworkTopology

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "PartitionSize"
objDevvarInst.Value = varPartitionSize

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "FullName"
objDevvarInst.Value = varFullName

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")

objDevvarInst.Name = "OrgName"
objDevvarInst.Value = varOrgName

' create device variable instance
objDevvarInst.Put_()
Call CheckForErrors("Failed: Put_() couldn't create device variable")
                
                        objDevvarInst.Name = "PublicIP"
                        objDevvarInst.Value = varPublicIP
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "PublicSubNet"
                        objDevvarInst.Value = varPublicSubNet
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "PublicGateway"
                        objDevvarInst.Value = varPublicGateway
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "PublicDNS"
                        objDevvarInst.Value = varPublicDNS
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "PublicNicName"
                        objDevvarInst.Value = varPublicNicName
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                
                        objDevvarInst.Name = "PublicMAC"
                        objDevvarInst.Value = varPublicMAC
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                                    
                            
                        objDevvarInst.Name = "PrivateIP"
                        objDevvarInst.Value = varPrivateIP
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "PrivateSubNet"
                        objDevvarInst.Value = varPrivateSubNet
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "PrivateGateway"
                        objDevvarInst.Value = varPrivateGateway
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "PrivateDNS"
                        objDevvarInst.Value = varPrivateDNS
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "PrivateNicName"
                        objDevvarInst.Value = varPrivateNicName
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                
                        objDevvarInst.Name = "PrivateMAC"
                        objDevvarInst.Value = varPrivateMAC
                        ' create device variable instance
                        objDevvarInst.Put_()
        
                        objDevvarInst.Name = "MPIIP"
                        objDevvarInst.Value = varMPIIP
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "MPISubNet"
                        objDevvarInst.Value = varMPISubNet
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "MPIGateway"
                        objDevvarInst.Value = varMPIGateway
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                    
                        objDevvarInst.Name = "MPIDNS"
                        objDevvarInst.Value = varMPIDNS
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                        
                        objDevvarInst.Name = "MPINicName"
                        objDevvarInst.Value = varMPINicName
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
                
                        objDevvarInst.Name = "MPIMAC"
                        objDevvarInst.Value = varMPIMAC
                        ' create device variable instance
                        objDevvarInst.Put_()
                        Call CheckForErrors("Failed: Put_() couldn't create device variable")
    


End Sub

'********************************************************************
'* Sub:     CheckForErrors
'*
'* Purpose: Check if there are any errors returned from the previous
'*          function call.
'*
'* Input:  [in]  strMsg  error string to display if there is an error
'*
'* Output:  displays the error string to the user
'*
'********************************************************************

Sub CheckForErrors(ByVal strMsg)
    Dim strErrDesc      ' to store err description
    Dim intErrNum       ' to store err number
    Dim objWbemErr      ' swbemlasterror object

    If Err.Number  Then
        intErrNum  =  Err.number 
        strErrDesc =  Err.Description 
        
        If strErrDesc = "" And Err.Number Then
            Set objWbemErr = CreateObject("WbemScripting.SWbemLastError")
            strErrDesc = objWbemErr.Description
            strErrDesc = Replace(strErrDesc, vbCRLF, " ")
        End If
        Wscript.Echo(strMsg & " failed: " & strErrDesc & " (0x" & CStr(Hex(intErrNum)) & ")")
        WScript.Echo("PLease check your CSV file and ADS installation") 
        Wscript.Quit(2) ' 2 is for error, 1 is warning   
    End If
       
End Sub