aideb
asked on
Scripted DNS server change on workstations
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.lo g
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
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.lo
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
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.
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("Wscr ipt.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
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("Wscr
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
ASKER
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
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry, didn't realise I hadn't assigned this to you before!
Cheers
Cheers