fbpx Program: Get Registry Items from Remote Machines | Windows PowerShell, Windows Server | HostingUltraso.com
24/7/365 Support

Program: Get Registry Items from Remote Machines

Discussion

Although PowerShell does not directly let you access and manipulate the registry of a remote computer, it still supports this by working with the .NET Framework. The functionality exposed by the .NET Framework is a bit more developeroriented than we want, so we can instead use a script to make it easier to work with.

Example 186 lets you list child items in a remote registry key, much like you do on the local computer. In order for this script to succeed, the target computer must have the remote registry service enabled and running.

Example 186. GetRemoteRegistryChildItem.ps1

############################################################################## ## ## GetRemoteRegistryChildItem.ps1 ## ## Get the list of subkeys below a given key. ## ## ie: ## ## PS >GetRemoteRegistryChildItem LEEDESK HKLM:\Software ## ##############################################################################

param( $computer = $(throw "Please specify a computer name."), $path = $(throw "Please specify a registry path") )

## Validate and extract out the registry key if($path match "^HKLM:\\(.*)") {

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey(

"LocalMachine", $computer) } elseif($path match "^HKCU:\\(.*)") {

$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey

("CurrentUser", $computer) } else {

WriteError ("Please specify a fullyqualified registry path " + "(i.e.: HKLM:\Software) of the registry key to open.") return }

## Open the key $key = $baseKey.OpenSubKey($matches[1])

## Retrieve all of its children foreach($subkeyName in $key.GetSubKeyNames()) {

## Open the subkey $subkey = $key.OpenSubKey($subkeyName)

## Add information so that PowerShell displays this key like regular ## registry key $returnObject = [PsObject] $subKey

Example 186. GetRemoteRegistryChildItem.ps1 (continued)

$returnObject | AddMember NoteProperty PsChildName $subkeyName $returnObject | AddMember NoteProperty Property $subkey.GetValueNames()

## Output the key $returnObject

## Close the child key $subkey.Close() }

## Close the key and base keys $key.Close() $baseKey.Close()

Help Category:

Get Windows Dedicated Server

Only reading will not help you, you have to practice it! So get it now.

Processor RAM Storage Server Detail
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 128 GB (SSD SATA) Configure Server
Intel Atom C2750 2.4 GHz 8c/8t 8 GB DDR3 1× 1 TB (HDD SATA) Configure Server
Intel Xeon E3-1230 v2 3.3 GHz 4c/8t 16 GB DDR3 1× 256 GB (SSD SATA) Configure Server
Intel Atom C2350 1.7 GHz 2c/2t 4 GB DDR3 1× 250 GB (SSD SATA) Configure Server

What Our Clients Say