DNS Suffix Search Order

Home Forums Scripting Windows Script Host DNS Suffix Search Order

This topic contains 2 replies, has 3 voices, and was last updated by Avatar cpeluso 8 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Avatar
    gnome
    Member
    #154300

    Can someone help me write a simple vbscript pull the DNS Suffix Search Order from multiple servers using a file (e.g. servers.txt) and output file to my server with the following extension (i.e. txt, csv or xls)

    ‘So far here’s what I have, see below. But this script reports the ‘DNSSearchOrder and Not the DNSSuffixSearchOrder. Can someone help.

    Const ForWriting = 2

    arrComputers = Array(“Server1, Server2”)

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objReport = objFSO.CreateTextFile(“dnsreport.csv”, ForWriting)

    objReport.WriteLine “Server Name,IP Address,Preferred DNS,Alternate DNS”

    For Each strComputer in arrComputers
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)

    Set colNetCards = objWMIService.ExecQuery _
    (“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)

    For Each objNetCard in colNetCards
    For Each objAddress in objNetCard.IPAddress
    strIP = objAddress
    Next
    On Error Resume Next
    strDNSServerSearchOrder = Join(objNetCard.DNSServerSearchOrder, “,”)
    Next

    objReport.WriteLine strComputer & “,” & strIP & “,” & strDNSServerSearchOrder
    Next

    objReport.Close

    Avatar
    Hobie
    Member
    #349698

    Re: DNS Suffix Search Order

    I found this with a little help from my friend google: (Modified to fit you existing code)

    Let me know if this works for you or not and I’ll see what else I can find.

    *NOTE* The array needs to have each item in quotes (“Item1″,”Item2″,”Item3”,etc)

    Const ForWriting = 2
    On Error Resume Next

    arrComputers = Array(“Sever1”, “Server2”)

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objReport = objFSO.CreateTextFile(“dnsreport.csv”, ForWriting)

    objReport.WriteLine “Server Name,IP Address,Preferred DNS,Alternate DNS”

    For Each strComputer in arrComputers
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)
    Set colNetCards = objWMIService.ExecQuery _
    (“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
    For Each objNetCard in colNetCards
    For Each objAddress in objNetCard.IPAddress
    strIP = objAddress
    Next
    Next

    For Each objNicConfig In colNetCards
    If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
    For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
    strDNSServerSearchOrder = Join(strDNSSuffix, “,”)
    Next
    End If
    Next
    objReport.WriteLine strComputer & “,” & strIP & “,” & strDNSServerSearchOrder

    Next

    objReport.Close
    [/CODE]

    TechNet Link: [url]http://technet.microsoft.com/en-us/library/ee692588.aspx[/url]
    Hobie[CODE]
    Const ForWriting = 2
    On Error Resume Next

    arrComputers = Array(“Sever1”, “Server2”)

    Set objFSO = CreateObject(“Scripting.FileSystemObject”)
    Set objReport = objFSO.CreateTextFile(“dnsreport.csv”, ForWriting)

    objReport.WriteLine “Server Name,IP Address,Preferred DNS,Alternate DNS”

    For Each strComputer in arrComputers
    Set objWMIService = GetObject(“winmgmts:\” & strComputer & “rootcimv2”)
    Set colNetCards = objWMIService.ExecQuery _
    (“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
    For Each objNetCard in colNetCards
    For Each objAddress in objNetCard.IPAddress
    strIP = objAddress
    Next
    Next

    For Each objNicConfig In colNetCards
    If Not IsNull(objNicConfig.DNSDomainSuffixSearchOrder) Then
    For Each strDNSSuffix In objNicConfig.DNSDomainSuffixSearchOrder
    strDNSServerSearchOrder = Join(strDNSSuffix, “,”)
    Next
    End If
    Next
    objReport.WriteLine strComputer & “,” & strIP & “,” & strDNSServerSearchOrder

    Next

    objReport.Close
    [/CODE]

    TechNet Link: http://technet.microsoft.com/en-us/library/ee692588.aspx
    Hobie

    Avatar
    cpeluso
    Member
    #381541

    Re: DNS Suffix Search Order

    Hi Hobie,
    First of all thank you for helping out.

    The script didn’t work. It gave me the servernames and ip only and the other information (i.e. DNS Suffix Search List Order) was not included on the output file. Maybe it’s the order that is in?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.