Edit Remote Registry Key PowerShell

Edit Remote Registry Key PowerShell

Hello,

We previously saw how to read the registry remotely. We can use a very similar method to open a registry key with write access as I explain the comments.

The PowerShell code to use will be pretty similar as the read operation, but we will use an overload of RegistryKey.OpenSubKey:

Edit Remote Registry Key PowerShell - Method Overload

Edit Remote Registry Key PowerShell – Method Overload

This allow us to open a remote registry key and write to it:

Edit Remote Registry Key PowerShell - Before

Edit Remote Registry Key PowerShell – Before

$NewValue = '111'
$Type = [Microsoft.Win32.RegistryValueKind]::String

$ComputerName = 'DC2-Core'
$Hive = [Microsoft.Win32.RegistryHive]::LocalMachine
$KeyPath = 'SOFTWAREMicrosoftNotepadDefaultFonts'
$Name = 'iPointSize'
 
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($Hive, $ComputerName)
$key = $reg.OpenSubKey($KeyPath, $true)

$key.SetValue($Name,$NewValue,$Type)
Edit Remote Registry Key PowerShell - After

Edit Remote Registry Key PowerShell – After

And voilà, the remote registry key is modified. You can edit a few types of registry items like this, you just need to change the $Type:

Edit Remote Registry Key PowerShell - Types

Edit Remote Registry Key PowerShell – Types

You can also create new sub keys with the CreateSubKey method and its overload:

Name Description
CreateSubKey(String)
Creates a new subkey or opens an existing subkey for write access.
CreateSubKey(String, Boolean)
Creates a new subkey or opens an existing subkey with the specified access.
CreateSubKey(String, Boolean, RegistryOptions)
Creates a new subkey or opens an existing subkey with the specified access.
CreateSubKey(String, RegistryKeyPermissionCheck)
Creates a new subkey or opens an existing subkey for write access, using the specified permission check option.
CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions)
Creates a subkey or opens a subkey for write access, using the specified permission check and registry options.
CreateSubKey(String, RegistryKeyPermissionCheck, RegistryOptions, RegistrySecurity)
Creates a subkey or opens a subkey for write access, using the specified permission check option, registry option, and registry security.
CreateSubKey(String, RegistryKeyPermissionCheck, RegistrySecurity)
Creates a new subkey or opens an existing subkey for write access, using the specified permission check option and registry security.
Edit Remote Registry Key PowerShell - CreateSubKey

Edit Remote Registry Key PowerShell – CreateSubKey

 

Leave a Reply