Solved

VBScript remove WINS in 2008 R2 domain

Posted on 2013-05-16
5
333 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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

16 Experts available now in Live!

Get 1:1 Help Now