February 7th, 2008 by Jeffery Hicks
Last updated on February 11th, 2008

Another topic that I’ve seen resurface in the forums I frequent is reading remote registries. If you know exactly what you’re looking for it doesn’t get any easier than using REG.EXE from the command line. Here are some examples from the command’s help:

Examples:

REG QUERY HKLM\Software\Microsoft\ResKit /v Version
Displays the value of the registry value Version

::**********NOTES**********
REM This script will the registry for the specified key.
REM The computer name and registry key value will be displayed.
REM You can specify a computername as a runtime parameter.

REM If you don’t specify a name, the script will query
REM the local machine.

REM If you want to save results run
REM RegQueryList.bat > results.txt

REM To process a list of computers use an expression like this:
REM for /f %s in (servers.txt) do @regquery.bat %s >> results.txt

REM If you don’t specify a computer, the local computer will
REM be queried.

::**********CONFIGURATION**********
REM Define the registry path to query. Do not use quotes.
REM Remote computers can query either HKLM or HKCU, although as
REM a practical matter you can really only use HKLM

set regPath=hklm\software\microsoft\windows NT\currentversion

REM Enter the registry key that you want the value of:
set regKey=RegisteredOwner

The script takes a computer name as a run time parameter. If you don’t specify one then the local computer will be queried.

The script is intended to return the value of a single registry key. There are two variables you need to edit in the script before running it. Of course, you may prefer to modify this script so you can pass keys and values as additional run time parameters.

To query a single computer, open a command prompt in your script directory and run something like this:

This entry was posted
on Thursday, February 7th, 2008 at 1:23 pm and is filed under Batch/CMD.
You can follow any responses to this entry through the RSS 2.0 feed.
Both comments and pings are currently closed.

Is there the possibility of you turning that RegQuery.bat into comparable PowerShell code. I was just working on reading some registry keys for a list of computers and was hoping it could be done easily in PowerShell.