This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.

Remove-RegistryKey

Synopsis

Removes registry keys, subkeys and values on a local or remote computer.

Syntax

  • Remove-RegistryKey [-Key] [-ComputerName] [-WOW64] [-Credential] [-WhatIf] [-Confirm]
  • Remove-RegistryKey [-Key] [ValueName] [-ComputerName] [-WOW64] [-Credential] [-WhatIf] [-Confirm]

Description

The Remove-RegistryKey cmdlet is used to delete registry keys and values on the local or a remote computer.

Parameters

  • Key The key to target. If the ValueName parameter is not specified the key will be removed. If the ValueName parameter is specified the key will remain in the registry, but the specified value will be removed.
  • ValueName Remove this value at the key specified.
  • ComputerName The computer against which to run the cmdlet. By default this parameter will be populated with the name of the local computer.
  • WOW64 Force the use of WOW64 redirection. By default this cmdlet bypasses WOW64 redirection on 64-bit systems and accesses the Windows registry directly. Using this parameter forces the cmdlet to access the redirected 32-bit registry. When specified for use against 32-bit systems this parameter has no effect.
  • Credential The credentials under which to run the cmdlet. By default this cmdlet will run as the current user. Using this parameter and the Get-PSCredential cmdlet you can specify an alternate set of credentials under which to execute this command.

Inputs

Remove-RegistryKey accepts the output of Get-RegistryKey as an input object. The Key, ValueName and ComputerName parameters each accept pipeline input by property name.

Outputs

Remove-RegistryKey makes changes directly to the Windows registry and does not output any Powershell objects.

Notes

By default, Remove-RegistryKey bypasses WOW64 redirection when accessing 64-bit systems. This ensures consistent behaviour across systems regardless of Powershell host. To access 32-bit portions of the registry on 64-bit systems the -WOW64 parameter can be used.

The Remove-RegistryKey cmdlet requires that the RPC service is started on the computer it is trying to access and that DNS services are available to resolve target host names.

Example 1

This command will delete the registry key 'SOFTWARE\MyCompany\MyProduct' in the local machine hive on the local computer:

Remove-RegistryKey HKLM:\SOFTWARE\MyCompany\MyProduct

Example 2

Identical to the first example, but targeted at a remote computer, this command will delete the registry key 'SOFTWARE\MyCompany\MyProduct' in the local machine hive of the computer PC01:

Remove-RegistryKey HKLM:\SOFTWARE\MyCompany\MyProduct -ComputerName PC01

Example 3

This command will delete the registry value 'installer' in the registry key 'SOFTWARE\MyCompany\MyProduct' in the local machine hive on the local computer:

Remove-RegistryKey HKLM:\SOFTWARE\MyCompany\MyProduct -ValueName Installer

Example 4

Identical to the first example, but utilizing piped input from the Get-RegistryKey cmdlet, this command will delete the registry key 'SOFTWARE\MyCompany\MyProduct' in the local machine hive on the local computer:

Get-RegistryKey HKLM:\SOFTWARE\MyCompany\MyProduct | Remove-RegistryKey