Solved

Use Powershell Script to Recursively Search Remote Registry

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

Does Powershell have you tied up in knots?

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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