v_b
v_b

Reputation: 225

Backup and delete registry with PowerShell

How to backup all the registry and delete specific registry values on a remote server in PowerShell?

$Registry = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Computer)
$RegistryKey = $Registry.opensubkey($RegistryPath,$true) ## $True = Write
$RegistryKeyValue = $RegistryKey.getvalue($RegistryKeyName)

$RegistryKey.DeleteValue("$RegistryKeyName") 
Write-Output "Removed registry key ($RegistryKeyName) on $Computer  `r "

I have tried this but not working.

Upvotes: 1

Views: 5355

Answers (1)

malexander
malexander

Reputation: 4680

I recommend you look at the PSRemoteRegistry module. It simplifies working with a remote registry.

Import-Module PSRemoteRegistry

Example:

$Computer="Computer01"
$RegistryKey="SOFTWARE\Test\Test"
Remove-RegKey -ComputerName $Computer -Hive LocalMachine -Key $RegistryKey 

Upvotes: 2

Related Questions