Solved

Update WINS entries throughout domain

Posted on 2008-10-07
30
770 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:mdmcq5
  • 14
  • 14
  • 2
30 Comments
 
LVL 28

Expert Comment

by:Michael Pfister
ID: 22668379
"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
 

Author Comment

by:mdmcq5
ID: 22668593
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22668700
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
 
LVL 28

Expert Comment

by:Michael Pfister
ID: 22668744
as far as I know a change of the WINS configuration won't go into effect without rebooting.
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22668760
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
 

Author Comment

by:mdmcq5
ID: 22669750
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22669831
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
 

Author Comment

by:mdmcq5
ID: 22670014
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22670680
Then the old script needs remade. I'll try to do it today.
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22673183
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
 

Author Comment

by:mdmcq5
ID: 22673362
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22673714
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
 

Author Comment

by:mdmcq5
ID: 22674045
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
 

Author Comment

by:mdmcq5
ID: 22678834
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22679615
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:mdmcq5
ID: 22679777
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22680043
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
 

Author Comment

by:mdmcq5
ID: 22687128
sciphre, I ran the code yesterday and it just sat there for a few hours with no output.
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22689910
Well, yes, but you should have the output logged in the c:\netshlog.txt file

In theory.
0
 

Author Comment

by:mdmcq5
ID: 22690013
the output file isn't being generated and I've confirmed it hasn't been placed outside the root of C: drive
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22690214
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
 
LVL 5

Accepted Solution

by:
sciphre earned 500 total points
ID: 22690220
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
 

Author Comment

by:mdmcq5
ID: 22690367
a ha! there we go now...
0
 

Author Comment

by:mdmcq5
ID: 22690376
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
 
LVL 5

Expert Comment

by:sciphre
ID: 22690400
If we ignore previous entries and write 4 it can be done, just say the word
0
 

Author Comment

by:mdmcq5
ID: 22690486
word
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22691267
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
 

Author Comment

by:mdmcq5
ID: 22721538
sciphre, have you had any time to work on the code?
0
 
LVL 5

Expert Comment

by:sciphre
ID: 22725155
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
 

Author Comment

by:mdmcq5
ID: 22725196
that should be fine..
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now