Functional but ugly (hey im not a programmer) script for teaming emulex NICs
'Teams 10Gb Emulex Nics into a failover Team
'Script to take the IP from the active emulex nic, enable any disabled emulex nic, then team them and reapply the IP to the team.
'Requires the Emulex teaming software to be installed.
' Enable any Emulex NICs which are disabled.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter where NetEnabled='False'and servicename='be2net'",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_NetworkAdapter instance"
Wscript.Echo "-----------------------------------"
'Wscript.Echo "NetEnabled: " & objItem.NetEnabled
Wscript.Echo "ProductName: " & objItem.ProductName
objitem.enable
Next
' Gets the IP, Subnet, and Gateway from the current active Emulex NIC
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration where servicename='be2net'",,48)
For Each objItem in colItems
'Wscript.Echo "-----------------------------------"
'Wscript.Echo "Win32_NetworkAdapterConfiguration instance"
' Wscript.Echo "-----------------------------------"
If isNull(objItem.DefaultIPGateway) Then
addy=objitem.MACaddress
'wscript.echo addy
Else
storeIP=objItem.IPAddress(0)
storeSubnet=objItem.IPSubnet(0)
storeDGW=objItem.DefaultIPGateway(0)
Wscript.Echo StoreIP
Wscript.Echo storeSubnet
Wscript.Echo storeDGW
End If
Next
' Run the Emulex utility to team the adapters into a Team Names 10GB_Team
Set WShell = WScript.CreateObject("WScript.Shell")
WShell.run "cmd /c ""C:\Program Files\Emulex\Nic Teaming\OCTeamCmd.exe"" create team failover:fbenabled 10GB_Team nic1 nic2",1
'Wait for team to be created and come back up
wscript.sleep 30000
'Search for the Teamed virtual adapter then reapply settings to the NIC.
'I could have had it pull the DNS but its just as easy to assign it directly
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and serviceName='EMLX'")
strIPAddress = Array(StoreIP)
strSubnetMask = Array(storeSubnet)
strGateway = Array(storeDGW)
'Adjust the following two DNS Entries if for a different environment!!
strDNS1 = "192.168.30.50"
strDNS2 = "192.168.30.51"
strGatewayMetric = Array(1)
arrDNSServers = Array(strDNS1, strDNS2)
'Sets the IP, subnet, and gateway back to the original IP
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
'Script to take the IP from the active emulex nic, enable any disabled emulex nic, then team them and reapply the IP to the team.
'Requires the Emulex teaming software to be installed.
' Enable any Emulex NICs which are disabled.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapter where NetEnabled='False'and servicename='be2net'",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_NetworkAdapter instance"
Wscript.Echo "-----------------------------------"
'Wscript.Echo "NetEnabled: " & objItem.NetEnabled
Wscript.Echo "ProductName: " & objItem.ProductName
objitem.enable
Next
' Gets the IP, Subnet, and Gateway from the current active Emulex NIC
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration where servicename='be2net'",,48)
For Each objItem in colItems
'Wscript.Echo "-----------------------------------"
'Wscript.Echo "Win32_NetworkAdapterConfiguration instance"
' Wscript.Echo "-----------------------------------"
If isNull(objItem.DefaultIPGateway) Then
addy=objitem.MACaddress
'wscript.echo addy
Else
storeIP=objItem.IPAddress(0)
storeSubnet=objItem.IPSubnet(0)
storeDGW=objItem.DefaultIPGateway(0)
Wscript.Echo StoreIP
Wscript.Echo storeSubnet
Wscript.Echo storeDGW
End If
Next
' Run the Emulex utility to team the adapters into a Team Names 10GB_Team
Set WShell = WScript.CreateObject("WScript.Shell")
WShell.run "cmd /c ""C:\Program Files\Emulex\Nic Teaming\OCTeamCmd.exe"" create team failover:fbenabled 10GB_Team nic1 nic2",1
'Wait for team to be created and come back up
wscript.sleep 30000
'Search for the Teamed virtual adapter then reapply settings to the NIC.
'I could have had it pull the DNS but its just as easy to assign it directly
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE and serviceName='EMLX'")
strIPAddress = Array(StoreIP)
strSubnetMask = Array(storeSubnet)
strGateway = Array(storeDGW)
'Adjust the following two DNS Entries if for a different environment!!
strDNS1 = "192.168.30.50"
strDNS2 = "192.168.30.51"
strGatewayMetric = Array(1)
arrDNSServers = Array(strDNS1, strDNS2)
'Sets the IP, subnet, and gateway back to the original IP
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
errDNS = objNetAdapter.SetDNSServerSearchOrder(arrDNSServers)
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Next
Comments
Post a Comment