Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

VBScript to query DNS properties for multiple servers

$
0
0

Hi guys,

I have put together a script that will query the DNS properties (Preferred and Advanced) of a remote computer. I need this script to query a text file that contains multiple server names (one on each line) and output the results into one file.

At the moment my script looks like this:

strComputer = "<computername>"

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

Set colAdapters = objWMIService.ExecQuery _
    ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
Set wshShell = WScript.CreateObject( "WScript.Shell" )	
n = 1
WScript.Echo
For Each objAdapter in colAdapters

strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
WScript.Echo "Server: " & strComputerName
   WScript.Echo "    DNS servers:"
   If Not IsNull(objAdapter.DNSServerSearchOrder) Then
      For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
         WScript.Echo "      " & objAdapter.DNSServerSearchOrder(i)
      Next
   End If

Next
 
Function WMIDateStringToDate(utcDate)
   WMIDateStringToDate = CDate(Mid(utcDate, 5, 2)  & "/" & _
       Mid(utcDate, 7, 2)  & "/" & _
           Left(utcDate, 4)    & " " & _
              Mid (utcDate, 9, 2) & ":" & _
                  Mid(utcDate, 11, 2) & ":" & _
                     Mid(utcDate, 13, 2))
End Function

Also, the output currrently looks a little messy:

Server: <servername>
    DNS servers:
Server: <servername>
    DNS servers:
Server: <servername>
    DNS servers:
      <ipaddress>
      <ipaddress>

I am hoping for a text file output as follows:

Server: <first servername>
    DNS servers:
      <ipaddress>
      <ipaddress>

Server: <second servername>
    DNS servers:
      <ipaddress>
      <ipaddress>

etc, etc...

Any help would be greatly appreciated.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>