Solved

Use Powershell Script to Recursively Search Remote Registry

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
copy-item script help 15 66
Powershell script; disk size 3 38
Powershell String Parsing with Regular Expression 19 38
Need some help with powershell script 5 35
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…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now