I am bad with VBScript and I need a script so that I can change the network properties on each workstation. I need to change the DNS properties and WINS servers, and I don't want to go around and manually change 150 PC's
Are you using DHCP? If so then you just need to change these options ont he DHCP server. If you are not then I suggest configuring DHCP and set the workstations accordingly.
i use 2 subs to do this, setstatic then setIPaddress, the oNIC class is simply
Class clsNIC
Public MACAddress
Public DNSServers
Public Gateway
Public SubnetMask
Public Disable
Public IPAddress
End Class
the clsNIC is created by reading an xml which contains device ipaddress information
Sub SetIP(ByRef objWMIService, ByVal oNIC)
Dim strMACAddress, colNetAdapters, objNetAdapter
Dim errEnable, arrIPAddress, arrSubnetMask, arrGateway, arrDNSServerSearchOrder
Dim strGatewayMetric
strGatewayMetric = Array(1)
strMACAddress = Replace(oNIC.MACAddress, "-", ":")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
If UCase(objNetAdapter.MACAddress) = UCase(strMACAddress) Then
If oNIC.IPAddress <> "" Then
arrIPAddress = Array(oNIC.IPAddress)
If oNIC.SubnetMask <> "" Then
arrSubnetMask = Array(oNIC.SubnetMask)
Else
arrSubnetMask = Array("255.255.0.0.")
End If
errEnable = objNetAdapter.EnableStatic(arrIPAddress, arrSubnetMask)
End If
If oNIC.Gateway <> "" Then
arrGateway = Array(oNIC.GateWay)
If IsArray(arrGateway) Then
errEnable = objNetAdapter.SetGateways(arrGateway, strGatewaymetric)
End If
Else
objNetAdapter.SetGateways(arrGateway)
End If
If oNIC.DNSServers <> "" Then
arrDNSServerSearchOrder = Split(oNIC.DNSServers, ",")
If IsArray(arrDNSServerSearchOrder) Then
errEnable = objNetAdapter.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
End If
Else
errEnable = objNetAdapter.SetDNSServerSearchOrder(arrDNSServerSearchOrder)
End If
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Else
Wscript.Echo "no match " & UCase(objNetAdapter.MACAddress) & "<>" & UCase(strMACAddress)
End If
Next
Set colNetAdapters = Nothing
End Sub
Sub setStatic(ByVal strMACAddress, ByRef objWMIService)
Dim colNetAdapters, objNetAdapter
Dim errEnable, errGateways, errdns1, errWINS
Dim strIPAddress, strSubnetMask, strGateway, strGatewayMetric, strDNSServerSearchOrder
Dim strWINSPrimaryServer, strWINSSecondaryServer
Dim i
strGatewayMetric = Array(1)
strMACAddress = Replace(strMACAddress, "-", ":")
Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each objNetAdapter in colNetAdapters
If UCase(objNetAdapter.MACAddress) = UCase(strMACAddress) Then
strIPAddress = ""
strSubnetMask = ""
strGateway = ""
strDNSServerSearchOrder = ""
strWINSPrimaryServer = objNetAdapter.WINSPrimaryServer
strWINSSecondaryServer = objNetAdapter.WINSSecondaryServer
If Not IsNull(objNetAdapter.IPAddress) Then
strIPAddress = objNetAdapter.IPAddress
For i = 0 To UBound(objNetAdapter.IPAddress)
WScript.Echo " IP address:" & objNetAdapter.IPAddress(i)
'strIPAddress = Array(objNetAdapter.IPAddress(i))
Next
End If
If Not IsNull(objNetAdapter.IPSubnet) Then
strSubnetMask = objNetAdapter.IPSubnet
For i = 0 To UBound(objNetAdapter.IPSubnet)
WScript.Echo " Subnet:" & objNetAdapter.IPSubnet(i)
'strSubnetMask = Array(objNetAdapter.IPSubnet(i))
Next
End If
If Not IsNull(objNetAdapter.DefaultIPGateway) Then
strGateway = objNetAdapter.DefaultIPGateway
For i = 0 To UBound(objNetAdapter.DefaultIPGateway)
WScript.Echo " Default gateway:" & objNetAdapter.DefaultIPGateway(i)
'strGateway = Array(objNetAdapter.DefaultIPGateway(i))
Next
End If
If Not IsNull(objNetAdapter.DNSServerSearchOrder) Then
strDNSServerSearchOrder = objNetAdapter.DNSServerSearchOrder
For i = 0 To UBound(objNetAdapter.DNSServerSearchOrder)
WScript.Echo " DNSServer:" & objNetAdapter.DNSServerSearchOrder(i)
'strGateway = Array(objNetAdapter.DefaultIPGateway(i))
Next
End If
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
If IsArray(strGateway) Then
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
End If
If IsArray(strDNSServerSearchOrder) Then
errdns1 = objNetAdapter.SetDNSServerSearchOrder(strDNSServerSearchOrder)
End If
If errEnable = 0 Then
WScript.Echo "The IP address has been changed."
Else
WScript.Echo "The IP address could not be changed."
End If
Else
Wscript.Echo "no match " & UCase(objNetAdapter.MACAddress) & "<>" & UCase(strMACAddress)
End If
Next
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.