Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update WINS settings with before and after results sent to a text file

Status
Not open for further replies.

Yodelaheho

IS-IT--Management
Mar 17, 2005
3
US
Hello All,
Below is my script for WINS settings. This one took quite a bit longer to figure out thatn the DNS settings (at least as far as dumping the before and after to a text file. Hope it helps!
Again, below the script is a detailed explanation that will help if you are new to scripting.

OPTION EXPLICIT
Const INPUT_FILE_NAME = "C:\DNSScript\ServerList.txt"
CONST OUTPUT_FILE_NAME = "C:\DNSScript\Results_UpdateWINSServerSettings.txt"
Const FOR_READING = 1

strPrimaryServer = "10.3.180.88"
strSecondaryServer = "10.3.180.94"

DIM objFSO, objFile, strcomputers, arrComputers
DIM objnewFSO, objnewFile, objnewcomputerlist
DIM strcomputer, objPing, objStatus, objWMIService
DIM colitems, objItem, i, strPrimaryServer, strSecondaryServer
DIM SetWins

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)

Set objnewFSO = CreateObject("Scripting.FileSystemObject")
Set objnewFile = objFSO.CreateTextFile(OUTPUT_FILE_NAME, True)
Set objnewcomputerlist = objFSO.OpenTextFile(OUTPUT_FILE_NAME, 1)

For Each strComputer In arrComputers
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
'wscript.echo objStatus.ReplySize
If IsNull(objStatus.ReplySize) Then
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Could not connect to computer: " & strComputer
Else
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Server: " & strComputer

Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
For Each objItem in colItems
'On Error Resume Next
If Not IsNull(objItem.WINSPrimaryServer) Then
objnewFile.WriteLine "WINS Primary Server Before: " & objItem.WINSPrimaryServer(i)
If Not IsNull(objItem.WINSSecondaryServer) Then
objnewFile.WriteLine "WINS Secondary Server Before: " & objItem.WINSSecondaryServer(i)

End If

SetWins = objItem.SetWINSServer(strPrimaryServer, strSecondaryServer)

End If

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "-------------------------------------------"

Next

Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
'wscript.echo objStatus.ReplySize
If IsNull(objStatus.ReplySize) Then
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Could not connect to computer: " & strComputer
Else
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Server: " & strComputer

Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
For Each objItem in colItems
'On Error Resume Next
If Not IsNull(objItem.WINSPrimaryServer) Then
objnewFile.WriteLine "WINS Primary Server After: " & objItem.WINSPrimaryServer(i)
If Not IsNull(objItem.WINSSecondaryServer) Then
objnewFile.WriteLine "WINS Secondary Server After: " & objItem.WINSSecondaryServer(i)
End If
End If
Next
End If
End If
Next
Next
Wscript.Echo "DONE"
___________________________________________________________________________________________________________________________
SCRIPT EXPLANATION:

OPTION EXPLICIT
Const INPUT_FILE_NAME = "C:\<folder>\<ServerList.txt>" (This is the location of a text file with your servers listed in them–Put whatever path and document name you want to in here)
CONST OUTPUT_FILE_NAME = "C:\<folder>\<Results_UpdateWINSServerSettings.txt>" (This is the location of a text file where the results will be posted to–Put whatever path and document name you want to in here)
Const FOR_READING = 1

strPrimaryServer = "X.X.X.X" (Enter the IP Addresses of your primary WINS Server)
strSecondaryServer = "X.X.X.X" (Enter the IP Addresses of your secondary WINS Server)

DIM objFSO, objFile, strcomputers, arrComputers (DIM statement = Declares variables and allocates storage space)
DIM objnewFSO, objnewFile, objnewcomputerlist
DIM strcomputer, objPing, objStatus, objWMIService
DIM colitems, objItem, i, strPrimaryServer, strSecondaryServer
DIM SetWins

Set objFSO = CreateObject("Scripting.FileSystemObject") (Set statement = Assigns an object reference to a variable or property)
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)

Set objnewFSO = CreateObject("Scripting.FileSystemObject")
Set objnewFile = objFSO.CreateTextFile(OUTPUT_FILE_NAME, True)
Set objnewcomputerlist = objFSO.OpenTextFile(OUTPUT_FILE_NAME, 1)

For Each strComputer In arrComputers (This is where the script starts to read the <ServerList.txt> file line-by-line and then creates the output file)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
For Each objStatus in objPing
'wscript.echo objStatus.ReplySize
If IsNull(objStatus.ReplySize) Then
objnewFile.WriteLine "------------------------" (If it cannot connect to the server, then it enters a separation line into the document and below that enters “Could not connect to computer: <ServerName>” so you know which servers in your list were not updated)
objnewFile.WriteLine "Could not connect to computer: " & strComputer
Else
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "------------------------" (Enters double separation lines into the document and below that enters “Server: <ServerName>”. The double lines make things easier to view in the final document)
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Server: " & strComputer

Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE") (Only checks the enabled adapters)

For Each objItem in colItems (This runs through each of the enabled adapters and updates the output document with "WINS Primary Server Before: <IPAddress>" and below that "WINS Secondary Server Before: <IPAddress>".)
'On Error Resume Next
If Not IsNull(objItem.WINSPrimaryServer) Then
objnewFile.WriteLine "WINS Primary Server Before: " & objItem.WINSPrimaryServer(i)
If Not IsNull(objItem.WINSSecondaryServer) Then
objnewFile.WriteLine "WINS Secondary Server Before: " & objItem.WINSSecondaryServer(i)

End If

SetWins = objItem.SetWINSServer(strPrimaryServer, strSecondaryServer) (This sets the new WINS records on each enabled adapter)

End If

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "-------------------------------------------" (Enters a single separation line in the document, to make things easier to read)

Next

Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
'wscript.echo objStatus.ReplySize
If IsNull(objStatus.ReplySize) Then
objnewFile.WriteLine "------------------------" (If it cannot connect to the server, then it enters a separation line into the document and below that enters “Could not connect to computer: <ServerName>” so you know which servers in your list were not updated)
objnewFile.WriteLine "Could not connect to computer: " & strComputer
Else
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

objnewFile.WriteLine "------------------------" (Enters double separation lines into the document and below that enters “Server: <ServerName>”). The double lines make things easier to view in the final document)
objnewFile.WriteLine "------------------------"
objnewFile.WriteLine "Server: " & strComputer

Set colItems = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE") (Again, only checks the enabled adapters)
For Each objItem in colItems (This, again, runs through all of the enabled adapters and updates the output document with "WINS Primary Server After: <IPAddress>" and below that "WINS Secondary Server After: <IPAddress>")
'On Error Resume Next
If Not IsNull(objItem.WINSPrimaryServer) Then
objnewFile.WriteLine "WINS Primary Server After: " & objItem.WINSPrimaryServer(i)
If Not IsNull(objItem.WINSSecondaryServer) Then
objnewFile.WriteLine "WINS Secondary Server After: " & objItem.WINSSecondaryServer(i)
End If
End If
Next
End If
End If
Next
Next
Wscript.Echo "DONE" (This will give you a pop up window that says “DONE” at the end to let you know the script is complete)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top