Solved

Use Powershell Script to Recursively Search Remote Registry

Posted on 2011-03-18
3
2,734 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
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 70

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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