Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Statically assign preferred Dns Address

Status
Not open for further replies.

keithvp

Instructor
Aug 10, 2000
19
0
0
US
Hello
I am using a script from TechNet to statically assign an IP address for In/Out of office purposes. The script is below. However, I also need to statically assign the preferred and secondary dns servers. What is the vbscript reference to dns for me to assign those addresses?
Thanks

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.1.141")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.1.100")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
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
 
strDNSServers=Array("10.10.10.10","20.20.20.20")
objNetAdapter.SetDNSServerSearchOrder(strDNSServers)

Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top