Petri.com forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > Windows Script Host
Petri.com is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

Need help with this script to change DNS/WINS

Need help with this script to change DNS/WINS

this thread has 5 replies and has been viewed 4224 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 19th December 2011, 06:00
certifiedgeek05 certifiedgeek05 is offline
Casual
Casual
 
 Join Date: Apr 2007
  6 month star 12 month star
 Location: Phoenix AZ - 85014
 Posts: 33
 Send a message via ICQ to certifiedgeek05 Send a message via AIM to certifiedgeek05 Send a message via MSN to certifiedgeek05 Send a message via Yahoo to certifiedgeek05 Send a message via Skype™ to certifiedgeek05
 Reputation: certifiedgeek05 is on a distinguished road (10)
Default Need help with this script to change DNS/WINS

Hello,
I have been working on this script for a couple and can't seen to get it to work. All the parts of the script seem valid. If anyone can lend an Eye that would be awesome. Suggestings are welcome.

I am trying to:
1. Set DNS and WINS
2. Apply it only to a named NIC
3. Would love to have some error logging.

Here is the script.

Code:
On Error Resume Next
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

strDNS1 = "192.168.20.150"
strDNS2 = "192.168.20.41"
strWins1 = "192.168.20.150"
strWins2 = "192.168.20.41"

Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID = 'CFN'",,48)  <- This is ,,fortyeight)
 
For Each objNicConfig In colNicConfigs  
  arrDNSServers = Array(strDNS1, strDNS2)  
  objNicConfig.SetDNSServerSearchOrder(arrDNSServers)  
  intSetWINS = objNicConfig.SetWINSServer(strWINS1, strWINS2)
  'If intSetWINSServer = 0 Then
    'WScript.Echo "Success! WINS & DNS servers configured."
  'ElseIf intSetWINSServer = 1 Then
    'WScript.Echo "WINS  & DNS servers configured, please reboot."
  'Else
    'WScript.Echo "Error!! Unable to configure WINS & DNS servers."
  'End If
Next

Last edited by Rems; 19th December 2011 at 19:47..
  #2  
Old 19th December 2011, 07:48
tehcamel's Avatar
tehcamel tehcamel is offline
Moderator
 
 Join Date: Mar 2009
  6 month star 12 month star
 Location: Melbourne
 Posts: 5,637
  Send a message via Skype™ to tehcamel
 Reputation: tehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to beholdtehcamel is a splendid one to behold (717)
Default Re: Need help with this script to change DNS/WINS

well.. where is it failing ?
__________________

Melbourne IT Support


Please do show your appreciation to those who assist you by leaving Rep Point
  #3  
Old 20th December 2011, 23:07
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Need help with this script to change DNS/WINS

The object does not support the SetDNSServerSearchOrder method because the Win32_NetworkAdapter class does support the SetDNSServerSearchOrder and the SetWINSServer methods.

The Win32_NetworkAdapter stores network connection information while IP configurations are stored in the Win32_NetworkAdapterConfiguration class.

The Win32_NetworkAdapterConfiguration class does support the methods.
But then again, you won't be able to get the adapter's name for comparison from the Win32_NetworkAdapterConfiguration class.

Bij using one of the properties of a certain class that also exist and is the same in an other class you are able to associate.

sample:
Code:
strDNS1  = "192.168.20.150"
strDNS2  = "192.168.20.41"
strWins1 = "192.168.20.150"
strWins2 = "192.168.20.41"
 
strComputer = "."
 
Set objWMIService = GetObject( _
    "winmgmts:\\" & strComputer & "\root\cimv2")
 
Set colNics = objWMIService.ExecQuery _
    ("Select DeviceID From Win32_NetworkAdapter " _
        & "Where NetConnectionID = " & _
        "'CFN'",,48)
 
For Each objNic in colNics
   Set colNicConfigs = objWMIService.ExecQuery _
      ("ASSOCIATORS OF {Win32_NetworkAdapter.DeviceID='" _
      & objNic.DeviceID & "'}" _
      & " WHERE AssocClass=Win32_NetworkAdapterSetting",,48)
 
   For Each objNicConfig In colNicConfigs
     objNicConfig.SetDNSServerSearchOrder Array(strDNS1, strDNS2)
     objNicConfig.SetWINSServer strWINS1, strWINS2
   Next

Next
/Rems
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts
  #4  
Old 28th December 2011, 00:48
Dumber's Avatar
Dumber Dumber is offline
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,173
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (844)
Default Re: Need help with this script to change DNS/WINS

Why not using Netsh.exe? Much easier I think...
http://www.petri.com/configure_tcp_ip_from_cmd.htm
__________________
Marcel
Technical Consultant
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
"No matter how secure, there is always the human factor."

"Enjoy life today, tomorrow may never come."
"If you're going through hell, keep going. ~Winston Churchill"

  #5  
Old 29th December 2011, 18:28
certifiedgeek05 certifiedgeek05 is offline
Casual
Casual
 
 Join Date: Apr 2007
  6 month star 12 month star
 Location: Phoenix AZ - 85014
 Posts: 33
 Send a message via ICQ to certifiedgeek05 Send a message via AIM to certifiedgeek05 Send a message via MSN to certifiedgeek05 Send a message via Yahoo to certifiedgeek05 Send a message via Skype™ to certifiedgeek05
 Reputation: certifiedgeek05 is on a distinguished road (10)
Default Re: Need help with this script to change DNS/WINS

Good Morning Dumber,
I did use a vbscript that read a txt file of servers and copied a batchfile that had the NetSH commands that worked but the difference between Windows 2000, 2003 and 2008 are a pain.

I couldn't get NetSH to work on Windows 2000 at all but managed to get 2003/2003 to. This required a lot of work and I think in this large of an environment a pure VBscript would have been better. Total server 834.

You can see the differences below with NetSH:

Windows 2008
netsh interface ip set dns "CFN" static 171.74.74.155 primary
netsh interface ip add dnsserver "CFN" 171.74.107.198 index=2


netsh interface ip set wins "CFN" static 171.74.163.196
netsh interface ip add winsserver "CFN" 171.74.107.15 index=2

Windows 2003
netsh interface ip set dns "CFN" static 171.74.74.155 primary
netsh interface ip add dns "CFN" 171.74.107.198 2

netsh interface ip set wins "CFN" static 171.74.107.15 primary
netsh interface ip add wins "CFN" 171.74.163.196 2

Thanks,
David

Quote:
Originally Posted by Dumber View Post
Why not using Netsh.exe? Much easier I think...
http://www.petri.com/configure_tcp_ip_from_cmd.htm
  #6  
Old 30th December 2011, 01:59
Dumber's Avatar
Dumber Dumber is offline
Moderator
 
 Join Date: Dec 2003
  6 month star 12 month star
 Location: The Netherlands
 Posts: 8,173
 Reputation: Dumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to beholdDumber is a splendid one to behold (844)
Default Re: Need help with this script to change DNS/WINS

Ah you didn't say that

And what about Powershell? This should work for at least all your windows 2003/2008 servers.
http://fatbeards.blogspot.com/2008/0...e-servers.html

Ok, Windows 2000 is nowadays a pain in the ass anyway
You might follow the following guides for using WMI for the good old servers.
http://technet.microsoft.com/en-us/l.../ee692588.aspx
http://technet.microsoft.com/en-us/l.../ee692589.aspx
__________________
Marcel
Technical Consultant
Netherlands
http://www.phetios.com
http://blog.nessus.nl

MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
"No matter how secure, there is always the human factor."

"Enjoy life today, tomorrow may never come."
"If you're going through hell, keep going. ~Winston Churchill"

Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A script to change usernames? Managor General Scripting 7 24th March 2011 21:11
Autologon and a password change- who wins? JDMils Active Directory 4 5th November 2007 11:31
Change S/N Script Please help matty_lynch General Scripting 4 30th September 2005 22:54
Change S/N Script matty_lynch General Scripting 1 29th September 2005 22:34
Change Permission VIA script doron General Scripting 4 29th April 2004 11:07


All times are GMT +3. The time now is 09:03.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri