Home » How to Delete Registry Key in PowerShell

How to Delete Registry Key in PowerShell

To delete a registry key in PowerShell, we can use the Remove-Item cmdlet along with the -Path parameter. The Remove-Item command removes the registry key from the path specified by the -Path parameter.

The following method shows how to remove a registry key in PowerShell.

Method 1: Delete a registry key in PowerShell

# Specify the path to the registry key
$registryPath = "HKLM:\Software\SysApp"

# Delete the registry key
Remove-Item -Path $registryPath -Recurse

The following example shows how to use this method.

Delete a Registry Key in PowerShell

Use the Remove-Item cmdlet in PowerShell with the registry key path to remove it from the registry store.

In the following example, the $registryPath variable holds the path of the registry key that you want to delete.

The Remove-Item cmdlet deletes the specified registry key. The -Recurse parameter ensures that all subkeys and values within the key are also deleted.

The following example shows how to do this with syntax.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# Specify the path to the registry key
$registryPath = "HKLM:\Software\SysApp"
# Delete the registry key
Remove-Item -Path $registryPath -Recurse
# Get the registry key
Get-Item -Path $registryPath
# Specify the path to the registry key $registryPath = "HKLM:\Software\SysApp" # Delete the registry key Remove-Item -Path $registryPath -Recurse # Get the registry key Get-Item -Path $registryPath
# Specify the path to the registry key
$registryPath = "HKLM:\Software\SysApp"

# Delete the registry key
Remove-Item -Path $registryPath -Recurse

# Get the registry key
Get-Item -Path $registryPath

This example removes a registry key “SysApp“. If we try to retrieve the registry key using the Get-Item cmdlet, it will throw an exception as “Get-Item: Cannot find path ‘HKLM:\Software\SysApp’ because it does not exist.

Conclusion

I hope the above article on deleting a registry key using the PowerShell Remove-Item cmdlet is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.