Powershell: Delete Registry Key On Remote Server

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.



3 Responses 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.

  2. wanker Says:

    Looks like this is meant to run locally from a server as there’re no servers defined. What if you wanted to run this remotely, and to multiple servers?

    • baraholka1 Says:

      Hiya Wayne,

      Perhaps this URL will assist ?

      From the URL:

      Run a Script
      To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.

      For example, the following command runs the DiskCollect.ps1 script on the Server01 and Server02 remote computers.

      Copy Code invoke-command -computername Server01, Server02 -filepath c:\Scripts\DiskCollect.ps1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: