1

I'm trying to delete leftover Sonic Wall registry keys. I keep getting the error

"Cannot delete a subkey tree because the subkey does not exist"

The key has children but should the Recurse parameter handle this whole deletion? Registry Screenshot

I'm using this PowerShell command

Remove-Item -Path "HKLM:\SOFTWARE\Sonicwall" -recurse
Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45

1 Answers1

0

Yes, you can remove the subkeys recursively using it. I am explaining in details:

Get-ChildItem can perform complex filtering capabilities

Get-ChildItem -Path "HKLM:\SOFTWARE\Sonicwall -Recurse 

would help you to atleast list down all the items that you want to delete.

The next thing you can do after confirming is pipe it further to Remove-item. That way you know what is being deleted.

You can remove contained items by using Remove-Item, but you will be prompted to confirm the removal if the item contains anything else.

Remove-Item -Path HKLM:\SOFTWARE\Sonicwall

This item has children and since you have not given -recurse. So you need to choose according to the options that would prompt.

However, if you do not wish to get the prompt and delete first all the items within but the HKLM:\SOFTWARE\Sonicwall, then what you can do is :

Remove-Item -Path HKLM:\SOFTWARE\Sonicwall\* -Recurse

Since you are looking for removal in one single shot with subkeys and everything, then you can use -Force for the same:

Remove-Item -Path HKLM:\SOFTWARE\Sonicwall -recurse -Force

Hope it gives you some idea on what you should be doing next.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • Your fix seems like I need to clear the subkeys first. Is there a way to just nuke the whole tree? – Will Volkmann Sep 13 '22 at 18:46
  • @WillVolkmann: Yes, just use `Remove-Item -Path HKLM:\SOFTWARE\Sonicwall -recurse`. Also you can do `Get-Item HKLM:\SOFTWARE\Sonicwal -recurse | Remove-Item -Force` – Ranadip Dutta Sep 14 '22 at 13:28
  • Thanks for the follow up, but these scripts do not work. Remove-Item -Path HKLM:\SOFTWARE\Sonicwall -recurse give me an error "Cannot delete a subkey tree because the subkey does not exist" and Get-Item HKLM:\SOFTWARE\Sonicwal -recurse | Remove-Item -Force gives me an error " Get-Item : A parameter cannot be found that matches parameter name 'recurse'. – Will Volkmann Sep 14 '22 at 15:37
  • @WillVolkmann: Because the name of the subkey is wrong then. With that name there is no subkey. If possible share the name of the key and subkeys, accordingly the line can be altered. copy paste the name of Registry Hive as it is. `SonicWall` – Ranadip Dutta Sep 14 '22 at 17:22
  • got it working, just need to put the recurse at the end. The proper command is this Get-Item HKLM:\SOFTWARE\Sonicwall | Remove-Item -Force -recurse thanks for the help – Will Volkmann Sep 14 '22 at 21:41