This script will configure an IP address, subnet mask, default gateway, and DNS servers for the specified connection.
10.1.1.1 is the default gateway. Change other setting accordingly.
' ------ INITIAL CONFIGURATION ------
strComputer = "."
strConnection = "Local Area Connection"
strIP = Array("10.1.1.50")
strMask = Array("255.255.255.0")
strGatewayIP = Array("10.1.1.1")
arrDNSServers = Array("4.1.1.1", "4.2.2.2")
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colNA = objWMI.ExecQuery("select * " & _
" from Win32_NetworkAdapter " & _
" where NetConnectionID = '" & strConnection & "'" )
for each objNA in colNA
set colNAConfig = objWMI.ExecQuery _
("ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='" & _
objNA.DeviceID & "'} " & _
" WHERE resultClass = win32_NetworkAdapterConfiguration ")
for each objNAConfig in colNAConfig
intRC = objNAConfig.EnableStatic(strIP,strMask)
intRC2 = objNAConfig.SetGateways(strGatewayIP)
if intRC = 0 and intRC2 = 0 then
WScript.Echo "IP address configured for " & strConnection
elseif intRC = 1 or intRC2 = 1 then
WScript.Echo "You must reboot for the changes to take effect for " & _
strConnection
else
WScript.Echo "There was an error configuring IP for " & _
strconnection & ": " & intRC & " and " & intRC2
end if
next
next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set Nics = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each Nic In Nics
intSetDNSServers = Nic.SetDNSServerSearchOrder(arrDNSServers)
If intSetDNSServers = 0 Then
WScript.Echo " DNS Servers set!"
Else
WScript.Echo " Error setting DNS server info."
End If
Next
We have 7 guests and no members online