#PSTip Access remote registry using PowerShell

Using the Microsoft.Win32.Registry class it is possible to access both–the local registry and, more importantly, the registry of a remote system. Using the PowerShell cmdlet this is unfortunately not possible. Ravikanth posted a similar tip in PowerShell Magazine in which he uses it to retrieve SQL instance names using remote registry.

The following code will retrieve a list of sub keys from the HKLM:\Software path in the registry on Server1 computer:

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,Server1) 

$RegSubKey = $Reg.OpenSubKey("System\CurrentControlSet")

$Values = $RegSubKey.GetSubKeyNames()

Using this information it is possible to extract a value from the subkey as well. The following code sample will extract the path parameter from the first subkey in the Software container.

$RegPath = Join-Path 'Software' $Values[1]


For more information about this class and the available methods please refer to the MSDN article:

RegistryKey Class

About the author: Jaap Brasser

Jaap is a Senior System Engineer in the Financial Services industry. He focuses on Microsoft and related technologies and has a passion for PowerShell. In his spare time he maintains his Blog, Twitter feed, @Jaap_Brasser, and contributes on the Official Scripting Guys Forum and Windows PowerShell TechNet forums

Related Posts