Kae Travis

Use PowerShell to Read Remote Registry

Posted on by in PowerShell

There are a couple of different ways we can use PowerShell to read remote registry.

The first method requires that the RemoteRegistry service is started, otherwise you will see an error message similar to:

Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found."

Here is an example:

$keyName = "SOFTWARE\Microsoft\.NETFramework"
$keyData = "InstallRoot"
$computer = "computername"
#start remote registry service
Set-Service -Name RemoteRegistry -ComputerName $computer -StartupType Manual -ErrorAction Stop
Start-Service -InputObject (Get-Service -Name RemoteRegistry -ComputerName $computer) -ErrorAction Stop
#read registry
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$regKey= $Reg.OpenSubKey($keyName)
$regVal = $RegKey.GetValue($keyData)
write-host "Win32" $regVal 

The second method doesn’t have a requirement to start the RemoteRegistry service, and instead uses WMI:

[uint32]$hklm = 2147483650
$keyName = "SOFTWARE\Microsoft\.NETFramework"
$keyData = "InstallRoot"
$computer = "computername"
$val = Invoke-WmiMethod -ComputerName $computer -Namespace root\default -Class stdregprov -name getstringvalue @($hklm, $keyName,$keyData)| select -ExpandProperty svalue
write-host "WMI" $val

Of course, there are even more methods that we can use to read remote registry using PowerShell. And the above examples could do with some more error trapping. But it’s enough to get you started!

Use PowerShell to Read Remote Registry
Use PowerShell to Read Remote Registry

Leave a Reply