#142976 - 2005-07-05 04:08 PM
Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
Hi!
I am assigned to change the WINS and DNS settings on a lot of computers that use static settings (i.e. not DHCP).
Is it possible to do this safely remotely? Using netsh from Microsoft for example?
What I want to do is: Change the WINS and DNS settings and keep the other settings intact.
We use NT/2000/XP clients in an AD domain.
Any remote way would be great! It does not have to be (but definitly can be) a script solution. I will do this machine by machine though, still, remotely would be great so that I can save some time.
|
|
Top
|
|
|
|
#142977 - 2005-07-05 05:46 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Yes it can be done, but why are you not using DHCP to alter the DNS settings once the client is set to use a DHCP server? Al_Po recently posted a UDF to enable DHCP
EnableDHCP() - Configures a NIC to use DHCP settings
|
|
Top
|
|
|
|
#142978 - 2005-07-06 12:34 AM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Well here's a start to a "Anti-EnableDHCP" UDF... its been tested some... but please test before using on production boxes.
Your silver platter code sir... 
Examples: ? setstaticipoptions("IPAddress","192.168.0.101,255.255.255.0") ? setstaticipoptions("DefaultGW","192.168.0.1") ? setstaticipoptions("WINSServers","192.168.0.10,192.168.0.11") ? setstaticipoptions("DNSServers","192.168.0.10,192.168.0.11") ? setstaticipoptions("DNSDomain","MyDomain2.Com")
Code:
function SetStaticIPOptions($Setting,$Value,optional $remotepc) dim $objWMIService, $colitems, $objnetadapter,$,$IP[0],$SM[0],$WS1,$WS2 $SetStaticIPOptions=1 if $remotepc="" $remotepc="." endif $objWMIService = GetObject("winmgmts:\\" + $remotepc + "\root\cimv2") if @error exit @error endif $colItems = $objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=-1") For Each $objNetAdapter In $colItems Select case $setting="DNSServers" $=$objNetAdapter.SetDNSServerSearchOrder(split($value,",")) if @error exit @error else $SetStaticIPOptions=0 endif case $setting="WINSServers" $WS1=split($value,",")[0] if ubound(split($value,","))>0 $WS2=split($value,",")[1] else $WS2="" endif $=$objNetAdapter.SetWINSServer($WS1,$WS2) if @error exit @error else $SetStaticIPOptions=0 endif case $setting="DNSDomain" $=$objNetAdapter.SetDNSDomain($value) if @error exit @error else $SetStaticIPOptions=0 endif case $setting="DefaultGW" $=$objNetAdapter.SetGateways(split($value,",")) if @error exit @error else $SetStaticIPOptions=0 endif case $setting="IPAddress" if instr($value,",")>0 $IP[0]=split($Value,",")[0] $SM[0]=split($value,",")[1] $=$objNetAdapter.EnableStatic($IP, $SM) if @error exit @error else $SetStaticIPOptions=0 endif endif endselect Next endfunction
|
|
Top
|
|
|
|
#142980 - 2005-07-06 12:47 AM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
I don't have 2k box to test on... but I didn't see anything that said "limited to XP".
Doc, do you want to be my test monkey?
|
|
Top
|
|
|
|
#142982 - 2005-07-07 11:13 AM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
Thanks for your script Allen! Altough I am not eager to try out something which isn't yet well tested. Also, as we are in a NT/2000/XP client environment a solution which could handle all those environments would benefit me a great deal.
Instead I am going for a netsh based solution:
My current netsh script Code:
pushd interface ip
delete dns name=lo addr=all delete wins name=lo addr=all
add dns name=lo addr=10.11.12.25 index=1 add dns name=lo addr=10.11.12.50 index=2
add wins name=lo addr=10.11.12.50 index=1 add wins name=lo addr=10.11.12.25 index=2
popd
The problem with the above is that despite the index values used above the result still is (part of ipconfig /all output):
Quote:
DNS Servers . . . . . . . . . . . : 10.11.12.25 10.11.12.50 Primary WINS Server . . . . . . . : 10.11.12.25 Secondary WINS Server . . . . . . : 10.11.12.50
They are in the same order as you can see. And I actually want 10.11.12.25 as the primary DNS and 10.11.12.50 as the primary WINS. Which I thought I did by adding the index values.. Hm.. Any suggestions fellas?
|
|
Top
|
|
|
|
#142984 - 2005-07-07 06:12 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Its been tested some... and I think you would find it to do what you need with little or no effort. Based on what I've read it should work for NT4 SP4 too... Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0 SP4 and later. I'd almost bet the requirements for using netsh are the same as using this WMI method.
|
|
Top
|
|
|
|
#142987 - 2005-07-07 11:19 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
I resemble that remark
|
|
Top
|
|
|
|
#142988 - 2005-07-08 09:13 AM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
It's not an option because it has been said that these machines should use static configuration, so that they are not dependent on the DHCP server to be online. Personally I would love to switch to DHCP as I don't think that security would be affected (as a redundant DHCP solution could be setup, which we do not have currently).
Anyway, it's not my decision to take and therefore isn't an option. If I had the authority to change how things are done in a lot of areas I would. As for now I can only comply with what others have decided and give my comments.
|
|
Top
|
|
|
|
#142991 - 2005-07-08 01:37 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
It looks like you didn't read my answer (and yes, I have talked to my boss). I do know the benefits of using DHCP.
Edited by thisistheurl (2005-07-08 01:39 PM)
|
|
Top
|
|
|
|
#142993 - 2005-07-08 03:36 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
I will keep it in mind. Maybe you are lucky enough to be able to decide things like that yourself. But it's a different story here with a lot of non technical things involved, company politics. The best technical solution isn't always possible, sad but true. Thanks for your feedback though!
|
|
Top
|
|
|
|
#142994 - 2005-07-08 03:56 PM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Yes, I did read your answer. You said:
Quote:
It's not an option because it has been said that these machines should use static configuration, so that they are not dependent on the DHCP server to be online.
Well, after the lease has been give out for the first time there is *no* dependancy on a DHCP server being online at all. If someone has told you that there is then they don't understand DHCP.
The only dependancy is that if a lease cannot be renewed it will eventually expire and the address will be given up.
The lease is renewed half-way through the leased period, and if the DHCP server is off-line at this time the client will continue to attempt to renew the lease periodically.
This means that if the lease period is set at the default (7 days) and your DHCP server fails you have ~3.5 days to get it working again before leases will start to expire. If you think you might have an outage of more than 3.5 days set your lease to something longer, say 30 days. That will give you two weeks to get your server up and running again.
The only other time that you will have an issue if the DHCP server is unavailable and where the client has explicitly released the lease, or where it has moved to a new subnet and the DHCP data it has (IP address / gateway) are not valid. Neither of these situations apply to "static" devices.
So maybe you still cannot use DHCP because you cannot get support for it and I can imagine how frustrating that is, but the next time someone implies that the DHCP server has to be up for DHCP clients to work you can put them straight.
For more reading:
|
|
Top
|
|
|
|
#142995 - 2005-07-11 11:48 AM
Re: Used netsh to change WINS/DNS settings for computers remotely?
|
thisistheurl
Fresh Scripter
Registered: 2005-04-27
Posts: 12
|
Thanks for the information! Much appreciated!
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1376 anonymous users online.
|
|
|