?
Solved

VBScript remove WINS in 2008 R2 domain

Posted on 2013-05-16
5
Medium Priority
?
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39171549
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39171556
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
ID: 39191228
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 1500 total points
ID: 39191902
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
ID: 39205175
Thank you very much for your prompt response.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 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