How do I change DNS Primary and Secondary Server IP addresses with WMI

We are installing new domain controllers with new static IP addresses.  I will therefore have to change the entries for the Primary and Secondary DNS Server entries in the TCPIP properties of the NIC card for each of our Windows XP workstations.  How can I do this with a WMI command for a range of IP addresses?  Thanks in advance!
drummer1960Information Security OfficerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Joseph DalyConnect With a Mentor Commented:
That script above doesnt allow you to do multiple machines. Basically it only runs it on the single local machine you run it on.

In the comments you can see the message below.
"This code will configure the local computer with two DNS servers: and"

So you would need to run this on all of the machines you would need to configure. You could do this with a logon script or some other remote code execution tool. You may want to take a look at PSexec for running the commands on a remote machine.
How many machines do you have to change this on?  It might be time to think about implementing a DHCP server.

At the same time, this might help:
Joseph DalyCommented:
Hmmm are you running DHCP? If so you can set your primary and secondary DNS server with options.
It would be option 6 for DNS servers.
Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

Joseph DalyCommented:
Real quick I just took a screenshot of my DHCP server options. I blanked out our DNS servers but you get the idea.
Joseph DalyCommented:
And here is a little VB script to do the same with WMI. Change the addresses to match your own.
' From the book "Windows Server 2003 Networking Recipes"
' This code will configure the local computer
'   with two DNS servers: and
strComputer = "."
arrDNSServers = Array("", "")
' --------- END CONFIGURATION ------
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!"
    WScript.Echo " Error setting DNS server info."
  End If

Open in new window

drummer1960Information Security OfficerAuthor Commented:
We run all Static IP addresses throughut our these options still apply?
The link I sent you or VB script posted by xxdcmast do.  You should really look into DHCP if you have many machines.  It provides a lot of flexibility in situations like this.  
Joseph DalyCommented:
The VB script I put up there will work for you then. But I would definitley say that going with a DHCP server is your best option. It isnt really that difficult to setup probably under an hour maybe a little more if its your first time. No more tracking static addresses, no more possibility of duplicate IP conflicts etc. Add in the server and scope options and you are looking good.

Step by step if you do decide to do a DHCP server install. 
drummer1960Information Security OfficerAuthor Commented:
In your script....I put the new IP addresses for our DNS servers in these two places...correct?
with two DNS servers: and and here arrDNSServers = Array("", "")

Where do I put the range of IP addresses for the affected XP workstations or this is to go in the logon script??

If it goes in the logon do I call it or insert it into our existing logon script?  I have never done this.  Sorry for such a dumb question....

We are actually looking at DHCP....just a lot going on right now and don't want to throw another thing into the mix.

drummer1960Information Security OfficerAuthor Commented:
xxdcmast: ----->  Would you be so kind to answer the question above.  Thanks so much!
Joseph DalyCommented:
What did you decide to use?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.