Update WINS entries throughout domain

Some EE genius just assisted me w/updating my preferred DNS entries via a vbs script.  

What I would like to do now is run a similar script to change the WINS entries.  There was one DNS/WINS server that had an IP change and I need to update the WINS entries to point to the new IP address.

If there's a script as easy as my DNS question, that would be perfect!
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_23778819.html?cid=748#a22664381

Thanks!
mdmcq5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael PfisterCommented:
"Stolen" from http://www.microsoft.com/germany/technet/datenbank/articles/600486.mspx
On Error Resume Next
 
strComputer = "."
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"
 
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _
 "  Attempting to set WINS primary and secondary servers ..."
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, _
   strWINSSecondaryServer)
  If intSetWINSServer = 0 Then
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 
 WScript.Echo VbCrLf & String(80, "-")
 
 Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer
  WScript.Echo "    Secondary WINS Server: " & _
   objNicConfig.WINSSecondaryServer
Next

Open in new window

0
mdmcq5Author Commented:
How does this code work?
Does it scan AD or can I request it pull the server names via a text file?  And also I do not want the servers to reboot.
0
sciphreCommented:
Warning: This is the above code worked into my AD routine, not my code.
Warning: There's no DRYRUN
Warning: It replaces ALL WINS servers on all servers in the OU, as in, it does things "the easy way" and assumes all your servers in that OU use exactly the same (new) WINS servers

If you want I can mod the old DNS script to update WINS, and give you full DRYRUN functionality and matched replace, but it was so much faster to do this way.
'New WINS Servers
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"
 
'user parameter - domain path
'example:  LDAPPath="LDAP://OU=Domain Controllers,dc=mydomain,dc=com"
'example2: LDAPPath="LDAP://CN=Computers,dc=mydomain,dc=co,dc=uk"
LDAPPath="LDAP://OU=Corp Servers,OU=US Servers,dc=us,dc=ad,dc=united,dc=com"
 
'user parameter - number of pings before considering a host to be dead - should probably be at least 2 in a production script, but this should work fine
pingno=1
 
On Error Resume Next
 
Set objOU = GetObject(LDAPPath)
objOU.Filter = Array("Computer")
 
For Each objComputer in objOU
strComputer = objComputer.CN
 
Set objShell = CreateObject("WScript.Shell")
 
strCommand = "ping -n " & pingno & " " & strComputer
 
Return = objShell.Run(strCommand,0,True)
 
If Return = 0 Then
 
' =====================================================================
 
' Insert your query code here
 
' =====================================================================
 On Error Resume Next
 
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _
 "  Attempting to set WINS primary and secondary servers ..."
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, _
   strWINSSecondaryServer)
  If intSetWINSServer = 0 Then
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 
 WScript.Echo VbCrLf & String(80, "-")
 
 Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer
  WScript.Echo "    Secondary WINS Server: " & _
   objNicConfig.WINSSecondaryServer
Next
 
 
' =====================================================================
 
' End Query code
 
' =====================================================================
 
 
Else
Wscript.StdOut.WriteLine vbTab & "NETWORK ERROR"
End If
Next

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Michael PfisterCommented:
as far as I know a change of the WINS configuration won't go into effect without rebooting.
0
sciphreCommented:
The script knows otherwise, if you read it - it will wanr you if you need to reboot for the configuration to take effect.
It does NOT reboot the servers by itself, but you might like to make a note which ones need to be rebooted and schedule them for 5 min downtime.
0
mdmcq5Author Commented:
sciphre, the easiest thing I could or would like to do, is pull the servers from the servers.txt file.  For some reason the servers OU is broken up into about 10 subsets.  Can you incorporate the txt file into the above script?
0
sciphreCommented:
This should do the trick. Same format for servers.txt as the other one - one per line, last line empty.
'New WINS Servers
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"
 
'user parameter - number of pings before considering a host to be dead - should probably be at least 2 in a production script, but this should work fine
pingno=1
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("servers.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
 
Set objShell = CreateObject("WScript.Shell")
 
strCommand = "ping -n " & pingno & " " & strComputer
 
Return = objShell.Run(strCommand,0,True)
 
If Return = 0 Then
 
' =====================================================================
 
' Insert your query code here
 
' =====================================================================
 On Error Resume Next
 
 Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 WScript.Echo VbCrLf & "Host Name: " & strComputer & VbCrLf & _
 "  Attempting to set WINS primary and secondary servers ..."
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, _
   strWINSSecondaryServer)
  If intSetWINSServer = 0 Then
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServer = 1 Then
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 
 WScript.Echo VbCrLf & String(80, "-")
 
 Set colNicConfigs = objWMIService.ExecQuery _
 ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
 
 For Each objNicConfig In colNicConfigs
  WScript.Echo VbCrLf & _
   "  Network Adapter " & objNicConfig.Index & VbCrLf & _
   "    " & objNicConfig.Description
  WScript.Echo "    Primary WINS Server: " & objNicConfig.WINSPrimaryServer
  WScript.Echo "    Secondary WINS Server: " & _
   objNicConfig.WINSSecondaryServer
Next
 
 
' =====================================================================
 
' End Query code
 
' =====================================================================
 
 
Else
Wscript.StdOut.WriteLine vbTab & "NETWORK ERROR"
End If
Loop

Open in new window

0
mdmcq5Author Commented:
the servers have anywhere between 2 to 4 DNS and WINS entries.  What I want to do is modify the outdated server IP with the new server IP so I don't want to modify any other entries and I'm not certain in what order the old entry is set, whether it's the first, second, third or forth.  It want that old value found, say 192.168.1.1 and changed to 192.168.151.1
0
sciphreCommented:
Then the old script needs remade. I'll try to do it today.
0
sciphreCommented:
WMI doesn't have the concept of tertiary and quaternary WINS servers I'm afraid.
Doesn't work like DNS did - can't even query them that are beyond 2.
0
mdmcq5Author Commented:
so what type of options do I have?
If I run the script and set primary, secondary, third and fourth, will it update all the entries or will it ADD to the entries to where there could be duplicates?
0
sciphreCommented:
It will SET the primary and the secondary, and with some work they can be "set if previous is wrong" as the DNS script did.
Absolutely no info on the third and fourth, could be anything, but you just can't find out via WMI.

The option i can think of that may work reasonably well is to run a netsh script on all servers (which can be done via a VBScript that calls psExec on all of them) and set the third and fourth WINS, but you still wouldn't be able to mix and match - it's set or don't set, can't "set if previous is wrong" automatically without somehow parsing previous output from netsh, which is over my head.

Could however get netsh to read you the old WINS into a file and you'd parse that with the ol'brain.

Set WshShell = Wscript.CreateObject("Wscript.Shell")
WshShell.Run "psexec """ & strComputer & " netsh >> c:\netshlog.txt"

We could run that remotely on all servers and then you'd read it and decide which need changing what, and these can be updated manually with the following commands:
Note however that it would STILL be sequential, you can't "update WINS4" you need to "set only one WINS, 192.168.1.1" then "add" three more.

psexec \\fqdn "netsh interface ip set wins name="Local Area Connection" static 192.168.1.1"
psexec \\fqdn "netsh interface ip add wins name="Local Area Connection" 192.168.1.2"
psexec \\fqdn "netsh interface ip add wins name="Local Area Connection" 192.168.1.3"
psexec \\fqdn "netsh interface ip add wins name="Local Area Connection" 192.168.1.4"

The whole thing owuld save you from needing to remote desktop into each box, but there's no simple way i can think of like we did with DNS.
Also, I'll be calling it a day any minute now.
0
mdmcq5Author Commented:
ok, so what can I run to see what the current settings are?  and it was easier pulling the server names from the txt file...
not familiar w/netsh
0
mdmcq5Author Commented:
I receive this error when I run netsh:
netsh>WshShell.Run "psexec """ & strComputer & " netsh >> c:\netshlog.txt"
The following command was not found: WshShell.Run "psexec """ & strComputer & "
netsh >> c:\netshlog.txt".

and I do have psexec
0
sciphreCommented:
That won't work without the VBScript wrapper, but I didn't have time to get the details down yesterday.
Here, try this, should give you a big list of servers and wins entries for all their cards - note the keyword ALL - including VMWare interfaces and others:
pingno=1
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("servers.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
 
Set objShell = CreateObject("WScript.Shell")
 
strCommand = "ping -n " & pingno & " " & strComputer
 
Return = objShell.Run(strCommand,0,True)
 
If Return = 0 Then
 
' =====================================================================
 
' Insert your query code here
 
' =====================================================================
 
 Set WshShell = Wscript.CreateObject("Wscript.Shell")
 WshShell.Run "psexec \\" & strComputer & " ""netsh interface ip show wins"" >> c:\netshlog.txt"
 
' =====================================================================
 
' End Query code
 
' =====================================================================
 
 
Else
Wscript.StdOut.WriteLine vbTab & "NETWORK ERROR"
End If
Loop

Open in new window

0
mdmcq5Author Commented:
ok, I started the run using cscript + vbs and the psexec windows just wouldn't stop - anwyay of running it silent w/out the windows?
0
sciphreCommented:
Yes, there is.
I also changed it to wait for each psExec to finish or you will probably not be able to match computer names to settings... that'd be a shame.
You'll need to have psexec in the folder, forgot to mention that too.
pingno=1
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("servers.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
 
Set objShell = CreateObject("WScript.Shell")
 
strCommand = "ping -n " & pingno & " " & strComputer
 
Return = objShell.Run(strCommand,0,True)
 
If Return = 0 Then
 
' =====================================================================
 
' Insert your query code here
 
' =====================================================================
 
 Set objShell2 = CreateObject("Wscript.Shell")
 strCommand = "echo " & strComputer & " >> c:\netshlog.txt"
 Return = objshell2.Run(strCommand,0,True)
 strCommand = "psexec.exe \\" & strComputer & " ""netsh interface ip show wins"" >> c:\netshlog.txt"
 Return = objShell2.Run(strCommand,0,True)
 
' =====================================================================
 
' End Query code
 
' =====================================================================
 
 
Else
Wscript.StdOut.WriteLine vbTab & "NETWORK ERROR"
End If
Loop

Open in new window

0
mdmcq5Author Commented:
sciphre, I ran the code yesterday and it just sat there for a few hours with no output.
0
sciphreCommented:
Well, yes, but you should have the output logged in the c:\netshlog.txt file

In theory.
0
mdmcq5Author Commented:
the output file isn't being generated and I've confirmed it hasn't been placed outside the root of C: drive
0
sciphreCommented:
What a stupid bug. Really sorry, I worked with several versions of the file and them melded the wrong ones in, and made a dumb assumption to boot.
This one's tested this time, and works well if psexec is in your path or working dir.
I've also done the not dumb thing and removed the absolute path from netshlog.txt, it will create it in your working directory.
netshlog is a bit verbose as i don't know how to filter out the non-physical interfaces from it's output as I was doing with WMI - to be honest i hate working with text, give me objects any day.

I've been really busy the last few days, sorry to keep you waiting - also, don't forget that there will be no script solution to conditionally write the new WINS servers.
It can be done (more accurately, I can do it) if you accept to replace all 4 WINS servers on the targets, but not otherwise.
0
sciphreCommented:
It does help if i attach the code, doesn't it.
pingno=1
 
On Error Resume Next
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("servers.txt",1)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.Readline
 
Set objShell = CreateObject("WScript.Shell")
 
strCommand = "ping -n " & pingno & " " & strComputer
 
Return = objShell.Run(strCommand,0,True)
 
If Return = 0 Then
 
' =====================================================================
 
' Insert your query code here
 
' =====================================================================
 
 Set objShell2 = CreateObject("Wscript.Shell")
 strCommand = "cmd.exe /c echo " & strComputer & " >> netshlog.txt"
 Return = objshell2.Run(strCommand,0,True)
 strCommand = "cmd.exe /c psexec.exe \\" & strComputer & " ""netsh"" interface ip show wins >> netshlog.txt"
 Return = objShell2.Run(strCommand,0,True)
 
' =====================================================================
 
' End Query code
 
' =====================================================================
 
 
Else
Wscript.StdOut.WriteLine vbTab & "NETWORK ERROR"
End If
Loop

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mdmcq5Author Commented:
a ha! there we go now...
0
mdmcq5Author Commented:
oh, and I would be interested in this:
"It can be done (more accurately, I can do it) if you accept to replace all 4 WINS servers on the targets, but not otherwise"

Most of the servers should have four entries, but some only have two.  If I could wipe all the entries and start from scratch, that would be perfect!
0
sciphreCommented:
If we ignore previous entries and write 4 it can be done, just say the word
0
mdmcq5Author Commented:
word
0
sciphreCommented:
I'll try to do it tomorrow, walked into a complication that happened to give me a good idea, but I'm too tired to do it at the mo.
0
mdmcq5Author Commented:
sciphre, have you had any time to work on the code?
0
sciphreCommented:
I've played with it a bit, it currently seems to work but will attempt to set wins for all interfaces, not just the physical ones (vmware networks in my case).
Is this ok ?
0
mdmcq5Author Commented:
that should be fine..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.