Powershell: Delete Registry Key On Remote Server

By baraholka1

Friends Of The Bitten Tadpole:

There wasn’t much in the way of examples on the greater Google for this one. One forum entry even said it was too difficult and suggested using regedit.exe, but in fact it is very easy. Look at the following example:

# Delete the Registry Key given in $deleteKey
Function DeleteRegistryKey($deleteKey)
{
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$Hive = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $RemoteMachine)
$Key = $Hive.DeleteSubKey($deleteKey)
}

DeleteRegistryKey “Software\Microsoft\Whatever”

Too easy.

Tags:

One Response to “Powershell: Delete Registry Key On Remote Server”

  1. BJT Says:

    But how about a directory hive with keys still in that hive? With this function, you can’t delete recursively. Nice and compact function, though.

Leave a Reply