Solved

VBScript remove WINS in 2008 R2 domain

Posted on 2013-05-16
5
332 Views
Last Modified: 2013-05-29
hello,

Is there a VBScript to remove the WINS entries for a list of servers and create a log as well? I have about 700 servers and need to remove all wins entries from them.

Thanks,
lal_gs
0
Comment
Question by:lal_gs
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
0
 
LVL 42

Expert Comment

by:sedgwick
Comment Utility
to remove wins entries from all servers, add txt file with server names, one on each line and run the script with loop:
On Error Resume Next
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list_server.txt")
do while not listFile.AtEndOfStream 
    strComputer =  listFile.ReadLine()

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

loop

Open in new window

0
 

Author Comment

by:lal_gs
Comment Utility
Thank you very much.

Is there a way to include a log file for this script so that we can find out on which servers this has been applied?

Thank you,

lal_gs
0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
Comment Utility
On Error Resume Next
strWINSPrimaryServer = "192.168.0.1"
strWINSSecondaryServer = "192.168.0.2"

Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list_server.txt")
Set logfile = fso.OpenTextFile("list_server.output.log", 2)
do while not listFile.AtEndOfStream 
    strComputer =  listFile.ReadLine()

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
  logfile.WriteLine objNicConfig & " Successfully set WINS servers."  
    WScript.Echo "    Successfully set WINS servers."
  ElseIf intSetWINSServer = 1 Then
  logfile.WriteLine objNicConfig & " Successfully set WINS servers, must reboot."  
    WScript.Echo "    Successfully set WINS servers." & _
     VbCrLf & "    Must reboot."
  Else
  logfile.WriteLine objNicConfig & " Unable to set WINS servers."  
    WScript.Echo "    Unable to set WINS servers."
  End If
Next
 logfile.Close
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

loop

Open in new window

0
 

Author Closing Comment

by:lal_gs
Comment Utility
Thank you very much for your prompt response.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

15 Experts available now in Live!

Get 1:1 Help Now