All,
I have been working with a scripter on writing a script to change the ipaddress of a network interface on a windows server. We think the script is right but when I run it I get an error that says "Invalid Parameter". They guy who has been writing the script for me says that the issue is
"
It seems that the EnableStatic method is not allowing the dynamic array created like,
Dim arrIPAddress()
It allows only the static Arrays created using Arrays() like
arrIPAddress = Arrays("192.168 .10.11")
"
Any help would be great. Below you will find a copy of the code.
Don
strComputer = "."
Set objWMIService = GetObject("winm gmts:" _
& "{impersonation Level=impersona te,(Shutdown)}! \\" & strComputer & "\root\cimv 2")
Set colNetAdapters = objWMIService.E xecQuery _
("Select * From Win32_NetworkAd apterConfigurat ion Where IPEnabled = True")
Dim arrIPAddress()
strGatewayMetri c = Array(1)
strSubnetMask1 = Array("255.255. 255.0")
strSubnetMask2 = Array("255.255. 0.0")
strGateway1 = Array("192.168. 30.1")
arrDNSServers1 = Array("192.168. 30.21", "192.168.30.22" )
strWINSPrimaryS erver1 = "192.168.30 .21"
strWINSSecondar yServer1 = "192.168.30 .22"
strGateway2 = Array("172.16.1 7.1")
arrDNSServers2 = Array("172.16.1 7.21", "172.16.17. 22")
strWINSPrimaryS erver2 = "172.16.17. 21"
strWINSSecondar yServer2 = "172.16.17. 22"
strGateway3 = Array("10.0.1.1 ")
arrDNSServers3 = Array("10.0.1.2 1", "10.0.1.22" )
strWINSPrimaryS erver3 = "10.0.1.21"
strWINSSecondar yServer3 = "10.0.1.22"
strSubnetMask = Array("")
strGateway = Array("")
arrDNSServers = Array("", "")
strWINSPrimaryS erver = ""
strWINSSecondar yServer = ""
For Each objNetAdapter in colNetAdapters
count = 0
ReDim arrIPAddress(0)
strSubnet = objNetAdapter.I PSubnet(0)
If strSubnet <> "" Then
subnet = Split(strSubnet , ".")
For Each strAddress in objNetAdapter.I PAddress
address = Split(strAddres s, ".")
strNetworkId = ""
For i = LBound(address) to UBound(address)
IPByte = address(i) And subnet(i)
strNetworkId = strNetworkId & IPByte
if i <> UBound(address) Then
strNetworkId = strNetworkId & "."
End If
Next
strHostId = ""
networdId = Split(strNetwor kId, ".")
For i = LBound(address) to UBound(address)
IPByte = address(i) Xor networdId(i)
strHostId = strHostId & IPByte
if i <> UBound(address) Then
strHostId = strHostId & "."
End If
Next
if strNetworkId = "128.222.82 .0" Then
strNetworkId = "128.222.92 .0"
strSubnetMask = strSubnetMask1
strGateway = strGateway1
arrDNSServers = arrDNSServers1
strWINSPrimaryS erver = strWINSPrimaryS erver1
strWINSSecondar yServer = strWINSSecondar yServer1
End If
if strNetworkId = "172.16.0.0 " Then
strNetworkId = "172.17.0.0 "
strSubnetMask = strSubnetMask2
strGateway = strGateway2
arrDNSServers = arrDNSServers2
strWINSPrimaryS erver = strWINSPrimaryS erver2
strWINSSecondar yServer = strWINSSecondar yServer2
End If
if strNetworkId = "10.10.0.0" Then
strNetworkId = "10.0.0.0"
strGateway = strGateway3
strSubnetMask = strSubnetMask3
arrDNSServers = arrDNSServers3
strWINSPrimaryS erver = strWINSPrimaryS erver3
strWINSSecondar yServer = strWINSSecondar yServer3
End If
networkId = Split(strNetwor kId, ".")
hostId = Split(strHostId , ".")
strNewIPAddress = ""
For i = LBound(networkI d) to UBound(networkI d)
IPByte = networkId(i) Or hostId(i)
strNewIPAddress = strNewIPAddress & IPByte
if i <> UBound(networkI d) Then
strNewIPAddress = strNewIPAddress & "."
End If
Next
ReDim arrIPAddress(co unt+1)
arrIPAddress(co unt) = strNewIPAddress
count = count + 1
Next
errAddress = objNetAdapter.E nableStatic( _
arrIPAddress, strSubnetMask)
errGateways = objNetAdapter.S etGateways(_
strGateway, strGatewaymetri c)
errDNS = objNetAdapter.S etDNSServerSear chOrder(_
arrDNSServers)
errWINS = objNetAdapter. SetWINSServer(_
strWINSPrimaryS erver, strWINSSecondar yServer)
End If
Next
' This will reboot the system.
Set colOperatingSys tems = objWMIService.E xecQuery _
("Select * from Win32_Operating System")
For Each objOperatingSys tem in colOperatingSys tems
ObjOperatingSys tem.Reboot()
Next
I have been working with a scripter on writing a script to change the ipaddress of a network interface on a windows server. We think the script is right but when I run it I get an error that says "Invalid Parameter". They guy who has been writing the script for me says that the issue is
"
It seems that the EnableStatic method is not allowing the dynamic array created like,
Dim arrIPAddress()
It allows only the static Arrays created using Arrays() like
arrIPAddress = Arrays("192.168 .10.11")
"
Any help would be great. Below you will find a copy of the code.
Don
strComputer = "."
Set objWMIService = GetObject("winm gmts:" _
& "{impersonation Level=impersona te,(Shutdown)}! \\" & strComputer & "\root\cimv 2")
Set colNetAdapters = objWMIService.E xecQuery _
("Select * From Win32_NetworkAd apterConfigurat ion Where IPEnabled = True")
Dim arrIPAddress()
strGatewayMetri c = Array(1)
strSubnetMask1 = Array("255.255. 255.0")
strSubnetMask2 = Array("255.255. 0.0")
strGateway1 = Array("192.168. 30.1")
arrDNSServers1 = Array("192.168. 30.21", "192.168.30.22" )
strWINSPrimaryS erver1 = "192.168.30 .21"
strWINSSecondar yServer1 = "192.168.30 .22"
strGateway2 = Array("172.16.1 7.1")
arrDNSServers2 = Array("172.16.1 7.21", "172.16.17. 22")
strWINSPrimaryS erver2 = "172.16.17. 21"
strWINSSecondar yServer2 = "172.16.17. 22"
strGateway3 = Array("10.0.1.1 ")
arrDNSServers3 = Array("10.0.1.2 1", "10.0.1.22" )
strWINSPrimaryS erver3 = "10.0.1.21"
strWINSSecondar yServer3 = "10.0.1.22"
strSubnetMask = Array("")
strGateway = Array("")
arrDNSServers = Array("", "")
strWINSPrimaryS erver = ""
strWINSSecondar yServer = ""
For Each objNetAdapter in colNetAdapters
count = 0
ReDim arrIPAddress(0)
strSubnet = objNetAdapter.I PSubnet(0)
If strSubnet <> "" Then
subnet = Split(strSubnet , ".")
For Each strAddress in objNetAdapter.I PAddress
address = Split(strAddres s, ".")
strNetworkId = ""
For i = LBound(address) to UBound(address)
IPByte = address(i) And subnet(i)
strNetworkId = strNetworkId & IPByte
if i <> UBound(address) Then
strNetworkId = strNetworkId & "."
End If
Next
strHostId = ""
networdId = Split(strNetwor kId, ".")
For i = LBound(address) to UBound(address)
IPByte = address(i) Xor networdId(i)
strHostId = strHostId & IPByte
if i <> UBound(address) Then
strHostId = strHostId & "."
End If
Next
if strNetworkId = "128.222.82 .0" Then
strNetworkId = "128.222.92 .0"
strSubnetMask = strSubnetMask1
strGateway = strGateway1
arrDNSServers = arrDNSServers1
strWINSPrimaryS erver = strWINSPrimaryS erver1
strWINSSecondar yServer = strWINSSecondar yServer1
End If
if strNetworkId = "172.16.0.0 " Then
strNetworkId = "172.17.0.0 "
strSubnetMask = strSubnetMask2
strGateway = strGateway2
arrDNSServers = arrDNSServers2
strWINSPrimaryS erver = strWINSPrimaryS erver2
strWINSSecondar yServer = strWINSSecondar yServer2
End If
if strNetworkId = "10.10.0.0" Then
strNetworkId = "10.0.0.0"
strGateway = strGateway3
strSubnetMask = strSubnetMask3
arrDNSServers = arrDNSServers3
strWINSPrimaryS erver = strWINSPrimaryS erver3
strWINSSecondar yServer = strWINSSecondar yServer3
End If
networkId = Split(strNetwor kId, ".")
hostId = Split(strHostId , ".")
strNewIPAddress = ""
For i = LBound(networkI d) to UBound(networkI d)
IPByte = networkId(i) Or hostId(i)
strNewIPAddress = strNewIPAddress & IPByte
if i <> UBound(networkI d) Then
strNewIPAddress = strNewIPAddress & "."
End If
Next
ReDim arrIPAddress(co unt+1)
arrIPAddress(co unt) = strNewIPAddress
count = count + 1
Next
errAddress = objNetAdapter.E nableStatic( _
arrIPAddress, strSubnetMask)
errGateways = objNetAdapter.S etGateways(_
strGateway, strGatewaymetri c)
errDNS = objNetAdapter.S etDNSServerSear chOrder(_
arrDNSServers)
errWINS = objNetAdapter. SetWINSServer(_
strWINSPrimaryS erver, strWINSSecondar yServer)
End If
Next
' This will reboot the system.
Set colOperatingSys tems = objWMIService.E xecQuery _
("Select * from Win32_Operating System")
For Each objOperatingSys tem in colOperatingSys tems
ObjOperatingSys tem.Reboot()
Next
Comment