Script to gather registry value from remote computers

Naheer
Naheer used Ask the Experts™
on
Need a script to check what is the registry value and get the out put in an text or excel format.
I need to run this script remotely on 2000+ server and get the output in one single file.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dan McFaddenSystems Engineer

Commented:
Can you post the reg key?

Dan

Author

Commented:
HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\1 this is the location of the registry value and on the right hand side there is a string with the name "PatchGroup" i need that value
Bill PrewTest your restores, not your backups...
Top Expert 2016

Commented:
How will the 2000+ servers be identified, do you have a list of them in a text file, or need to search AD, etc?

~bp
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Technical Designer
Commented:
Create a batch file and include the following line in it. This would give you what is inside the PatchGroup
REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\1p /v PatchGroup

To redirect the output of the same to a text file modify the command to the following:
REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\1p /v PatchGroup > C:\reg_result.txt

You could change the name of the output file to what ever you like.

Run the batch in logon script or through Group Policy.

You could also redirect the output to the a single file on the remote server, for that the command would change slightly.
REG QUERY HKEY_LOCAL_MACHINE\SOFTWARE\XYZ\1p /v PatchGroup >> \\DC\SharedFolder\reg_result.txt

There are other ways of doing it like Powershell.

Thanks,
Sudeep

Author

Commented:
How to run it against the 2000+ server there should be some file which will be calling these servers.

I have the server list handy.
Dan McFaddenSystems Engineer
Commented:
Here's your script:

$ServerList = Get-Content ServerList.txt
$RegBasePath = "LocalMachine"
$RegSubKey = "SOFTWARE\XYZ\1"
$RegStringName = "PatchGroup"
$OutputFile = "ServerRegKey.csv"
$Output = @()

foreach ($server in $ServerList)
{
  Write-Host "Working on server::  " $server
  $Hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($RegBasePath, $server)
  $RegKey = $Hive.OpenSubKey($RegSubKey)
  $StringValue = $RegKey.GetValue($RegStringName)
  
  $rinfo = New-Object PSObject
  $rinfo | Add-Member -MemberType NoteProperty -Name  "Server" -Value $server
  $rinfo | Add-Member -MemberType NoteProperty -Name  "Registry-BasePath" -Value ($RegBasePath)
  $rinfo | Add-Member -MemberType NoteProperty -Name  "Registry-SubKey" -Value ($RegSubKey)
  $rinfo | Add-Member -MemberType NoteProperty -Name  "Registry-String" -Value ($RegStringName)
  $rinfo | Add-Member -MemberType NoteProperty -Name  "Registry-Value" -Value ($StringValue)
  $Output += $rinfo
}

$Output | Export-Csv $OutputFile  -NoTypeInformation -UseCulture

Open in new window


1. The script file and the server list file should reside in the same directory
2. The file with the server names in it should be called "ServerList.txt"
3. The script variables at the top of the script can be adjusted to handle any registry location
4. The output file is written to the same directory the script is in

Dan

Author

Commented:
Thanks Dan I see the script provided is Powershell but i have some 2003 and 200 server also where is can't run this script can you please provide it in VB or batch file.
Dan McFaddenSystems Engineer

Commented:
You could use the batch that Sudeep posted above.  Would seem to fit your needs.

Dan
In the future please pick a more meaningful thread title.  "Script" does not help.  Perhaps "Search for registry key on multiple servers" would have been better.

The experts here are all volunteers.  And it makes it easier for all of us to skim titles to see if it's an area we have interest or expertise in.

Author

Commented:
As I have mixed environment I wanted kind of vbscript
I had some manual work. Script reduced my work 90 %.

Thanks for you solution

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial