Search code examples
powershellregistry

cannot remove registry key based on data value search


Working on a PowerShell script to remove registry key based on value search.

The goal of my script is to search from the root level for the data "values" then remove this key.

How can I search for value2 In the attached image ?

Get-ChildItem -Recurse -Force -Path hkcr:\

enter image description here enter image description here


Solution

  • There are only two registry drives available which you can query using the Get-PSDrive cmdlet:

    Get-PSDrive -PSProvider Registry
    

    Result:

    Name Used (GB) Free (GB) Provider Root               CurrentLocation
    ---- --------- --------- -------- ----               ---------------
    HKCU                     Registry HKEY_CURRENT_USER                 
    HKLM                     Registry HKEY_LOCAL_MACHINE     
    

    However, you can create a registry drive for HKEY_CLASSES_ROOT using the New-PSDrive cmdlet:

    New-PSDrive -PSProvider registry -Root HKEY_CLASSES_ROOT -Name HKCR
    

    Now you are be able to search in there using the Get-ChildItem cmdlet:

    Get-ChildItem -Recurse -Force -Path hkcr:/*/OpenWithList