Solved

Use Powershell Script to Recursively Search Remote Registry

Posted on 2011-03-18
3
2,872 Views
Last Modified: 2012-05-11
I have a script that I can use to remotely search a local registry for a subkey and get it's value.

I need to do a similar script that will search remote computers once provided with the computer name.


I read that I need to use .Net for remote access but it doesn't seem that it'll work


$values = ''
$MachineName = hostname                                                                            

$key = Get-ChildItem registry::HKU -recurse	-include Lotus -ErrorAction silentlycontinue | Select-Object -first 1 
$sub = Get-ChildItem Registry::$key -recurse -include Installer

$values = Get-ItemProperty $sub.PSPath
$values.PROGDIR

Open in new window

0
Comment
Question by:MaxZetoX
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
Learnctx earned 500 total points
ID: 35170710
Done this one up quickly, maybe not the nicest script you'll ever use :) But for this example, it will search all subkeys below SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318} for a value of DeviceInstanceID and return the data stored in that value.
Function Reg-Query ($target, $key)
{
	try
	{
        $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $target)
        foreach ($sub in $reg.OpenSubKey($key).GetSubKeyNames())
        {
            $subkey = $reg.OpenSubKey("$($key)\$($sub)")
            foreach ($value in $subkey.GetValueNames())
            {
                if ($value -eq $targetvalue)
                {
                    $subkey.GetValue($value)
                    break
                }
            }
            Reg-Query -target $computer -key "$($key)\$($sub)"
        }
	} catch [System.Security.SecurityException] {
        "ACCESS DENIED: $($key)"
	} catch {
        $_.Exception.Message
    }
}

cls
$computer = "computernamehere"
$rootkey = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}"
$targetvalue = "DeviceInstanceID"
Reg-Query -computer $target -key $rootkey

Open in new window

0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 35687986
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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