Your strategic advantage starts here

Use PowerShell to Read Remote Registry

Use PowerShell to Read Remote Registry

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!

Related Posts
Leave a Reply
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day
Give us a call

Available from 9am to 8pm, Monday to Friday.

Send us a message

Send your message any time you want.

Our usual reply time: 1 Business day