Configures IP over InfiniBand networking. This script contributed by Markus Christen and Wayne Plourde of Microsoft.

Visual Basic
Edit|Remove
'----------------------------------------------------------------------------
' ADS Installation Script HPC
' Purpose: Change IP
' Version: 5.2
' Data     : 21.03.06
' Owner: Markus Christen / MCS Brazil - Wayne Plourde / MCS Federal
'----------------------------------------------------------------------------

Option Explicit
'On Error Resume Next
Err.Clear

Dim strComputer

Dim strIPAddressMPI
Dim strSubnetMaskMPI
Dim strMPINicName

Dim Return

Dim objWMIService

strComputer = "."

strIPAddressMPI = "^ADS_MPIIP^"
strSubnetMaskMPI = "^ADS_MPISUBNET^"
strMPINicName = "MPI"



Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Return = ChangeIP ("020000000001",strIPAddressMPI,strSubnetMaskMPI,0,0)
    'Return = SetConnectionName (strMACMPI,strMPINicName)


function ChangeIP (StrMAC,strIP,strSubnet,strGateway,strDNS)
        Dim strChangeMac
        Dim objNetAdapter
        Dim colNetAdapters
        Dim strIPAddress
        Dim strSubnetMask
        Dim myShell
        Set myShell = WScript.CreateObject("WScript.Shell")
        
        strChangeMac = ConvertMAC(StrMAC)
        Set colNetAdapters = objWMIService.ExecQuery _
            ("Select * from Win32_NetworkAdapter where MACAddress = '"& strChangeMac &"'")
        
        If colNetAdapters.count    = 0 then
            wscript.echo vbCRLF & "   ***** WARNING ******* - Device not Found!" & vbCRLF
        End If    
        
        For Each objNetAdapter in colNetAdapters
            wscript.echo "trying to set " & strChangeMac 
            wscript.echo objNetAdapter.NetConnectionID
            wscript.echo objNetAdapter.Description
            wscript.echo "IP: " & trim(strIP) & " - MASK: " & strSubnet

            myShell.Exec("netsh interface ip set address """ & objNetAdapter.NetCOnnectionID & """ static addr=" & strIP & " mask=" & strSubnet)
                
        Next

        'check that value is set
        Set colNetAdapters = objWMIService.ExecQuery _
            ("Select * from Win32_NetworkAdapterConfiguration where MACAddress = '"& strChangeMac &"'")
        
        For Each objNetAdapter in colNetAdapters
            wscript.echo "IP: " & objNetAdapter.IPAddress(0) & " (set)"

            If Trim(strIP) <> objNetAdapter.IPAddress(0) then

                wscript.echo vbCRLF & "  ***** WARNING ******  - IP NOT SET" & vbCRLF
            End If
            
        Next
        ChangeIP = 0
end function


function ConvertMAC (StrMAC)
        Dim StrMACAdress,StrMACAdress1,StrMACAdress2,StrMACAdress3,StrMACAdress4,StrMACAdress5,StrMACAdress6
        StrMACAdress = StrMAC
        StrMACAdress1 = Mid(StrMACAdress, 1, 2)
        StrMACAdress2 = Mid(StrMACAdress, 3, 2)
        StrMACAdress3 = Mid(StrMACAdress, 5, 2)
        StrMACAdress4 = Mid(StrMACAdress, 7, 2)
        StrMACAdress5 = Mid(StrMACAdress, 9, 2)
        StrMACAdress6 = Mid(StrMACAdress, 11, 2)
        StrMACAdress = StrMACAdress1 &":"&StrMACAdress2&":"&StrMACAdress3&":"&StrMACAdress4&":"&StrMACAdress5&":"&StrMACAdress6
        ConvertMAC = StrMACAdress
end function



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

Sub CheckForErrors( ByVal strMessage )
      If Err.Number <> 0 Then
      WScript.Echo strMessage & " Error #0x" & Hex( Err.Number ) & ": " & Err.Description
      Wscript.Quit(2) ' 2 is for error, 1 is warning
   End If

End Sub

function SetConnectionName (StrMAC,StrConnectionNewName)
            Dim objWMIService
            Dim colItems
            Dim objItem
            Dim strPath
            Dim Wshshell
            Dim strChangeMac 
            Set WshShell = WScript.CreateObject("WScript.Shell")
            strChangeMac = ConvertMAC(StrMAC)
    
            Set objWMIService = GetObject("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        
            Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter where MACAddress ='"& strChangeMac &"'")
            
            For Each objItem in colItems
                strPath = "%comspec% /Q /C  NETSH interface set Interface name="""&objItem.NetConnectionID&""" newname="""&StrConnectionNewName&""""
                return=WshShell.run (strPath,0)
                Call CheckForErrors("Failed Return Code: " & return)
            Next
end function