Changing WINS Server address to a bunch of Servers using VBScript


When my company started Active Directory project, we setup a new WINS server running on Windows 2003 server. We replaced our old Windows NT WINS server with new Windows 2003 server.

 

It’s easy to change the new WINS server information to the Desktops. DHCP server was the easy place to distribute the WINS server to all Desktop in one shot. BUT, What about the Servers in Data center with manual IP address mapping? Here I come with a script as below.

 

I used WMI objects to get the network properties and change the WINS address.

 

If you want to reuse this script, you need the following information ready.

  1. ServersList.txt – a text file with server names one in each line
  2. Primary and Secondary WINS server IP address
  3. First two or three octects of your production network IP address

The third requirement is little tricky. If your production network IP address of a server is 192.168.0.44, then you need to provide "192.168" to the script (check the script). If the IP Address goes like this 10.20.30.10, then you need to provide "10.20.30". I hope you get the idea.

 

I always create a log file with these kinds of scripts. This script will create a log file in running directory as WinsChange.log. It’s very handy to check back which servers were applied with new WINS and which ones failed (got to do manually).

 

CAUTION: This script works only Windows 2000 and above OSes.

 

You need to change the values in this script where you find “<<<<<” in comments

 

‘ Script Purpose: To change the WINS server information in Network properties to a bunch of computers/servers

‘ Written by: Anand Venkatachalapathy

On Error Resume Next

 

Dim fso, fin, fout

Set fso = CreateObject("Scripting.FileSystemObject")

Set fin = fso.OpenTextFile("ServerList.txt", 1, True)

Set fout = fso.OpenTextfile("WinsChange.log",2, True)

 

Do While NOT fin.AtEndOfStream

            ChangeWINS(fin.ReadLine)

Loop

 

fin.Close

fout.Close

 

Sub ChangeWINS(strComputer)

WScript.Echo "———" & strComputer & "——————"

fout.WriteLine "———" & strComputer & "——————"

 

strWINSPrimaryServer = "xx.xx.xx.xx"          ‘<<<Provide your primary WINS server IP address

strWINSSecondaryServer = "yy.yy.yy.yy"      ‘<<<Provide your secondary WINS server IP address

 

Set objWMIService = GetObject("winmgmts:" _

 & "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

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

 

            strIPAddress = Join(objNicConfig.IPAddress,",")

            WScript.Echo "Working on network interface: " & strIPAddress

            fout.WriteLine "Working on network interface: " & strIPAddress

            If InStr(strIPAddress,"x.x") > 0 then                         ‘<<<<< Provide your starting two octects of IP address

                                                                                                ‘This is important, because we want to change the IP address only

                                                                                                ‘ to production network card.  This logic will skip the backup area network

                                                                                                ‘cards, loopback cards and disabled network cards

                        WScript.Echo VbCrLf & "  Network Adapter " & objNicConfig.Index & VbCrLf & "    " & objNicConfig.Description

                        fout.WriteLine "  Network Adapter " & objNicConfig.Index & "    " & objNicConfig.Description

                        intSetWINSServer = objNicConfig.SetWINSServer(strWINSPrimaryServer, strWINSSecondaryServer)

 

                        If intSetWINSServer = 0 Then

                                    WScript.Echo "    Successfully set WINS servers."

                                    fout.WriteLine "    Successfully set WINS servers."

                        ElseIf intSetWINSServer = 1 Then

                                    WScript.Echo "    Successfully set WINS servers." & VbCrLf & "    Must reboot."

                                    fout.WriteLine "    Successfully set WINS servers." & VbCrLf & "    Must reboot."

                        Else

                                    WScript.Echo "    Unable to set WINS servers."

                                    fout.WriteLine "    Unable to set WINS servers."

                        End If

            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 Sub

One thought on “Changing WINS Server address to a bunch of Servers using VBScript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s