Solved

Scripted DNS server change on workstations

Posted on 2012-03-20
6
696 Views
Last Modified: 2012-05-28
I am looking for scripted solution to change the DNS settings on a number of workstations which have statically assigned IP addresses (and therefore DNS settings).

All the workstations are in a domain and I will probably use group policy to deploy the script.

I created a script myself which used NETSH however a number of the workstations are in other languages and therefore the adapter name is different. Also, on some machines people have renamed the adapters.

The clients are mainly Windows XP but there are also some Windows 2000, Vista and Windows 7

Incase anything goes wrong and settings need to be reverted I need to log the before and after to C:\Temp\Networksettings.log

Some machines have multiple adapters and therefore I want to ensure that only the adapter with a 10.x.x.x address range have their DNS servers changed.

The DNS servers need to be
10.44.99.1
10.44.99.2


BTW - I know that these clients *should* be configured to use DHCP but we have other issues preventing that at the moment!

Thanks
0
Comment
Question by:aideb
6 Comments
 
LVL 38

Expert Comment

by:Adam Brown
ID: 37743749
You'd use the NETSH utility in the command prompt to do this. http://www.petri.co.il/configure_tcp_ip_from_cmd.htm has more info.
0
 
LVL 17

Expert Comment

by:Gaurav Singh
ID: 37743764
Dim strIPAddress
Dim strSubnetMask
Dim strGateway
Dim intGatewayMetric
Dim strDns1
Dim strDns2

strIPAddress = "10.10.10.50"
strSubnetMask = "255.255.255.0"
strGateway = "10.10.10.1"
intGatewayMetric = 1
strDns1 = "10.10.10.9"
strDns2 = "10.10.10.10"

Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.Run "netsh interface ip set address name=""Local Area Connection"" static " & strIPAddress & " " & strSubnetMask & " " & strGateway & " " & intGatewayMetric, 0, True
objShell.Run "netsh interface ip set dns name=""Local Area Connection"" static "& strDns1, 0, True
objShell.Run "netsh interface ip add dns name=""Local Area Connection"" addr="& strDns2, 0, True
Set objShell = Nothing
WScript.Quit
0
 
LVL 2

Author Comment

by:aideb
ID: 37746053
acbrown2010 - The problem I have with Netsh as I noted above is that the interface name is often different between machines. It requires you to specify the name of the interface. Thats why I need a scripted solution.

systechadmin: Again, anything that references the name of the interface will fail as some are renamed, some are in French, others are in German. Also, I only want to change the DNS servers and not the IP address,mask or gateway

Thanks for your suggestions so far
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:BigRedRPB
ID: 37747319
Hey aideb,

Give this one a shot (remember to run as Admin on Vista/7).  I pulled this from a much larger script and tweaked it for what you are looking for so let me know if you run into any issues.

Kevin
SetDNS.vbs
0
 
LVL 3

Accepted Solution

by:
BigRedRPB earned 500 total points
ID: 37747443
Sorry, forgot that you wanted to log the old servers.  Here's an update.
SetDNS.vbs
0
 
LVL 2

Author Closing Comment

by:aideb
ID: 38019285
Sorry, didn't realise I hadn't assigned this to you before!

Cheers
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

896 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

14 Experts available now in Live!

Get 1:1 Help Now