tstout7152
IS-IT--Management
So I am trying to use Microsoft script for gathering DNS information from my servers. Rather than edit the vbscript each time to enter a server name, or create a script for each server, I want alter the script to read a text file that contains a list of server names and then execute the command against each server listed in the text file.
While I do have this somewhat working, I am running into a problem where each sequential server is outputing DNS info from the servers above in addition to its own.
Can someone tell me what I am missing?
Thanks,
Terry
While I do have this somewhat working, I am running into a problem where each sequential server is outputing DNS info from the servers above in addition to its own.
Can someone tell me what I am missing?
Thanks,
Terry
Code:
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile ("c:\scripts\servers.txt", ForReading)
i = 0
Do Until objFile.AtEndOfStream
strNextLine = objFile.Readline
If strNextLine <> "" Then
objDictionary.Add i, strNextLine
End If
i = i + 1
Loop
objFile.Close
For Each strLine in objDictionary.Items
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strLine & "\root\cimv2")
Set colNicConfigs = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfigs
strDNSSuffixSO = ""
strDNSServerSO = ""
strDNSHostName = objNicConfig.DNSHostName
strIndex = objNicConfig.Index
strDescription = objNicConfig.Description
strDNSDomain = objNicConfig.DNSDomain
strDNSSuffixSO = ""
If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
strDNSSuffixSO = strDNSSuffixSO & VbCrLf & String(37, " ") & _
strDNSSuffix
Next
End If
strDNSServerSO = ""
If Not IsNull(objNicConfig.DNSServerSearchOrder) Then
For Each strDNSServer In objNicConfig.DNSServerSearchOrder
strDNSServerSO = strDNSServerSO & VbCrLf & String(37, " ") & _
strDNSServer
Next
End If
strDomainDNSRegistrationEnabled = _
objNicConfig.DomainDNSRegistrationEnabled
strFullDNSRegistrationEnabled = objNicConfig.FullDNSRegistrationEnabled
strDNSSettings = strDNSSettings & VbCrLf & VbCrLf & _
" Network Adapter " & strIndex & VbCrLf & _
" " & strDescription & VbCrLf & VbCrLf & _
" DNS Domain: " & strDNSDomain & VbCrLf & _
" DNS Domain Suffix Search Order:" & strDNSSuffixSO & VbCrLf & _
" DNS Server Search Order:" & strDNSServerSO & VbCrLf & _
" Domain DNS Registration Enabled: " & _
strDomainDNSRegistrationEnabled & VbCrLf & _
" Full DNS Registration Enabled: " & _
strFullDNSRegistrationEnabled
Next
WScript.Echo VbCrLf & "DNS Settings" & VbCrLf & VbCrLf & _
"Host Name: " & strDNSHostName & strDNSSettings
Next