• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

Query Registry for DNS suffix setting

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
SearchList

Does someone have a quick script for this issue?
0
mystikal1000
Asked:
mystikal1000
  • 2
  • 2
1 Solution
 
X_layerCommented:
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.
0
 
Steve KnightIT ConsultancyCommented:
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.

Steve
@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

0
 
Krzysztof PytkoActive Directory EngineerCommented:
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
http://technet.microsoft.com/en-us/sysinternals/bb897553

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

Regards,
Krzysztof
0
 
Steve KnightIT ConsultancyCommented:
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?!

Steve
0
 
Krzysztof PytkoActive Directory EngineerCommented:
Yeah, that's resonable, if you have more than one NIC :) Good to remember, thanks :)

Krzysztof
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now