Read Remote Registry PowerShell
Hello,
You may used to read the registry of a remote computer with RegEdit.exe and “Connect Network Registry” (Require “Remote Registry service running on remote computer):
With PowerShell, there is a provider that allow us to browse the local registry just like a local drive :
Get-ItemProperty -Path HKLM:SOFTWAREMicrosoftNotepadDefaultFonts -Name iPointSize
Read Remote Registry PowerShell
If you want to read the registry from a remote computer, you can use “Invoke-Command”, this require you to setup PowerShell Remoting (Enable-PSRemoting) first:
Invoke-Command -ComputerName DC2-Core -Command {Get-ItemProperty -Path HKLM:SOFTWAREMicrosoftNotepadDefaultFonts -Name iPointSize}
If you can’t use PowerShell Remoting, you can use .Net to query a remote computer. To do that, you need use the “Microsoft.Win32.RegistryKey” .Net class.
First, prepare some variables for later use :
$ComputerName = 'DC2-Core' $Hive = 'LocalMachine' $KeyPath = 'SOFTWAREMicrosoftNotepadDefaultFonts' $Value = 'iPointSize'
Then, create the RegistryKey object :
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("$hive", "$ComputerName")
Use the “OpenRemoteBaseKey” method :
$key = $reg.OpenSubKey("$KeyPath")
And finally, get the value :
$key.GetValue($Value)
Wrapup
So hereunder, all the lines together:
$ComputerName = 'DC2-Core' $Hive = [Microsoft.Win32.RegistryHive]::LocalMachine $KeyPath = 'SOFTWAREMicrosoftNotepadDefaultFonts' $Value = 'iPointSize' $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive, $ComputerName) $key = $reg.OpenSubKey($KeyPath) $key.GetValue($Value)
You see the possible values of “Microsoft.Win32.RegistryHive” with IntelliSense or, with :
[Enum]::GetValues('Microsoft.Win32.RegistryHive')
Edit Remote Registry PowerShell
As asked in the comments, I published a very basic example about how to edit remote registry:
https://github.com/edemilliere/Misc/blob/master/Set-RemoteRegistryKey.ps1
The process is quite similar as reading, but you’ll notice that I used an Overload of the OpenSubKey method to tell I need to edit the subkey.
This example will work with PowerShell in version 2, without PowerShell Remoting enabled.
But, how i can correct some registry key from remote pc? =(
Just need to use the overload of OpenSubKey :
$key=$reg.OpenSubKey(\”$KeyPath\”,$true)
The $true tells that you open the subkey with intent to edit it.
Thank you for being concise, just what I needed and the last comment about $True for editing was the final piece of the puzzle. All I needed to do was read a value and then delete it. (Remotely)
Regards,
DeployGuy
Pingback: Get Windows Update Configuration PowerShell - It for DummiesIt for Dummies
what kind of entitlements are needed for this? can a power user do this or is it administrator privileges only
By default it’s administrator only