Best way to clean up registry keys

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of CHARALABOS CHARALABOS 1 year, 2 months ago.

  • Author
  • #28605
    Profile photo of CHARALABOS

    Hello community,
    I am searching the most efficient way to work with registry, to clean up some keys (subkeys specifically).
    How can I achieve best results? Working with Remove-Item cmdlet with a registry path? Or work with WMI ?

    Thank you in advance...

  • #28607
    Profile photo of Rob Simmers
    Rob Simmers

    That really depends on how you intend to execute this change on the systems. Does it need to work remotely? If I was removing a lot of keys the easiest method would probably using regedit.exe, export the keys, edit the .REG file and place the minus sign ( – ) next to anything you want removed and then run "regedit /s removestuff.reg" on the systems. How do you intend to actually execute this update?

  • #28608
    Profile photo of Wilfredo Perez
    Wilfredo Perez

    Powershell makes it very easy to remove reg keys from the registry and it fast. I would make a backup of the key, just in case.
    EX: remove-item hklm:\software\mycompany\OldApp

  • #28609
    Profile photo of CHARALABOS

    Thank you for the replies.
    First of all I want to work with Registry through PowerShell, that's why I posted my question here.
    I realize that it is very significant to firstly export all the registry to a file (backup) an then do some stuff.
    After this I don't need to work remotely.
    Is the best choice to use remove-item cmdlet for my needs? Or is there any other way to work with WMI?

  • #28610
    Profile photo of Curtis Smith
    Curtis Smith

    The answer to your question is, "It Depends". You can definitely do the work through WMI with PowerShell, You can also do the work with regedit.exe, reg.exe, remote-item, etc., etc., etc. through PowerShell. The best choice will depend on requirements and skill set. If this is a one time use scenario and just need a solution, that's easy to just knock out, regedit.exe or reg.exe may be the best choice. If you need to hit remote machine, but don't know how to use WMI, or remove-item, reg.exe may be the best choice. If you are well versed in WMI and need something that is repeatable, that may be your best choice. If your choice requires the best performance, then you will need to do some performance testing with the different options to see which process is best for your environment. measure-command is available in PowerShell to help you do that performance testing.

  • #28623
    Profile photo of CHARALABOS

    Thank you all!!

You must be logged in to reply to this topic.