![]() |
|
|
|||||||
| Petri.co.il is happy to award auglan the title of Most Valuable Member !!! |
| Register | Calendar |
Search |
Today's Posts |
Mark Forums Read |
| Notices |
|
|
Need help with this script to change DNS/WINSthis thread has 5 replies and has been viewed 2154 times
|
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||||||||
|
||||||||||
|
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
|
|||||||||||
|
|||||||||||
|
well.. where is it failing ?
__________________
Posting from a BB Playbook - please excuse my typing |
|
#3
|
||||||||||
|
||||||||||
|
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
__________________
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
|
||||||||||
|
||||||||||
|
Why not using Netsh.exe? Much easier I think...
http://www.petri.co.il/configure_tcp_ip_from_cmd.htm
__________________
Marcel 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. |
|
#5
|
||||||||||
|
||||||||||
|
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:
|
|
#6
|
||||||||||
|
||||||||||
|
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 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. |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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 |