Solved

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

Posted on 2009-06-29
11
1,020 Views
Last Modified: 2012-05-07
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!
0
Comment
Question by:drummer1960
  • 6
  • 3
  • 2
11 Comments
 
LVL 7

Expert Comment

by:rcflyr
ID: 24739744
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:
http://www.serverwatch.com/tutorials/article.php/1556311
0
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 24739751
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.

http://technet.microsoft.com/en-us/library/cc958929.aspx
0
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 24739771
Real quick I just took a screenshot of my DHCP server options. I blanked out our DNS servers but you get the idea.
1.jpg
0
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 24739782
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: 192.168.1.151 and 192.168.1.152

' ------ SCRIPT CONFIGURATION ------

strComputer = "."

arrDNSServers = Array("192.168.1.151", "192.168.1.152")

' --------- 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!"

  Else

    WScript.Echo " Error setting DNS server info."

  End If

Next

Open in new window

0
 
LVL 1

Author Comment

by:drummer1960
ID: 24739915
We run all Static IP addresses throughut our domain....do these options still apply?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 7

Expert Comment

by:rcflyr
ID: 24739926
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.  
0
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 24740025
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.
http://www.windowsnetworking.com/articles_tutorials/DHCP_Server_Windows_2003.html
0
 
LVL 1

Author Comment

by:drummer1960
ID: 24740175
In your script....I put the new IP addresses for our DNS servers in these two places...correct?
with two DNS servers: 192.168.1.151 and 192.168.1.152 and here arrDNSServers = Array("192.168.1.151", "192.168.1.152")

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 script....how 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.

0
 
LVL 1

Author Comment

by:drummer1960
ID: 24748804
xxdcmast: ----->  Would you be so kind to answer the question above.  Thanks so much!
0
 
LVL 35

Accepted Solution

by:
Joseph Daly earned 250 total points
ID: 24753691
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: 192.168.1.151 and 192.168.1.152"

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.
0
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 24754094
What did you decide to use?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
CISCO ASA 5500 DDNS 4 54
Creating a correct SPF record 4 53
IPV6 and AWS 3 54
DNS Scavenging configuration 5 19
Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
Sometimes people don't understand why download speed shows differently for Windows than Linux.Specially, this article covers and shows the solution for throughput difference for Windows than a Linux machine. For this, I arranged a test scenario.I…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now