Query Registry for DNS suffix setting

Posted on 2011-10-18
Last Modified: 2012-06-27
I need a Batch or VBS script that can give me results on a number of servers.

I need to check the registry to verify the dns suffixes on over 200 servers..  HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

Does someone have a quick script for this issue?
Question by:mystikal1000
    LVL 11

    Expert Comment

    With VBScript you can easy read registry:
    Dim objWSH, strRegKey, strSearchListValue
    Set objWSH = WScript.CreateObject("WScript.Shell")
    strRegKey = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\SearchList"
    strSearchListValue= objWSH.RegRead(strRegKey)
    WScript.Echo strSearchListValue

    Open in new window

    You can modify this script that would write some log file on some share and run this script on your servers.
    LVL 43

    Accepted Solution

    Assuming you have a file called "servers.txt" with all the servers listed in it one server per line then this batch file (save it in notepad as findvalue.cmd say) will make you a CSV file of them all.

    @echo off
    setlocal enabledelayedexpansion
    set results="results.txt"
    set serverlist="servers.txt"
    set tempfile="temp.txt"
    del %results% 2>NUL
    REM Runs down each line in servers.txt.  Tries to get registry value from each
    REM If an error occurs, e.g. not available or access denied then it shows **ERROR ##**
    for /f "usebackq" %%s in (%serverlist%) do (
      echo Looking at %%s
      reg query \\%%s\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v SearchList > %tempfile%
      echo !errorlevel!
      if errorlevel 1 (
        echo Server %%s - Error retrieving values
        echo %%s,**ERROR !errorlevel!** >>%results%
      ) ELSE (
        set Result=
        for /f "usebackq tokens=3 delims= " %%R in (`find "REG_SZ" ^< %tempfile%`) do set Result=%%R
          echo Server %%s - "!Result!"
          echo %%s,!Result! >>%results%
    del %tempfile% 2>NUL
    START "Results of scan" %results%

    Open in new window

    LVL 39

    Expert Comment

    by:Krzysztof Pytko
    I think, that's better to use "ipconfig /all" with "find" output using PsExec. It's much more simple and will display the same DNS suffixes.

    Download PsExec from MS

    create a batch file with these commands

    ipconfig /all | find /i "DNS Suffix Search List" >%computername%.log

    and run PsExec

    PsExec \\computer-name -u AdminUserOnThatServer -p PasswordForAdminUser -c <path-to-batch-file>

    you can create text file with server names and instead of \\computer-name use @ServerListFileName

    LVL 43

    Expert Comment

    by:Steve Knight
    Well nowt wrong with a psexec method, is great tool but reg query \\%%s\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters /v SearchList

    isn't exactly difficult... I've just added a batch wrapper around to deal with errors, stripping just the results of that field and the like.

    Main reason I didn't use ipconfig /all myself is that on my machine and a couple of others I looked at the contents of the DNS Suffix search list reflect the completion domains specified on an adaptor but not the value in the key requested, that is what I returned the key he asked for instead?!

    LVL 39

    Expert Comment

    by:Krzysztof Pytko
    Yeah, that's resonable, if you have more than one NIC :) Good to remember, thanks :)


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now