powershellregistrywindows-11powershell-7.2

How to refer to HKEY_CLASSES_ROOT in PowerShell?


New-Item -Path "HKCR:\Directory\Background\shell\customname" -Force

I've been doing the same thing for HKCU and KHLM but when I try HKCR I get errors in PowerShell. how am I supposed to do it for HKEY_CLASSES_ROOT?

I searched for a solution but couldn't find any.


Solution

  • Defining a custom drive whose root is HKEY_CLASSES_ROOT, as shown in your own answer, is definitely an option, especially for repeated use.

    Ad hoc, you can alternatively use the Registry:: provider prefix directly with native registry paths:

    New-Item -Path 'Registry::HKEY_CLASSES_ROOT\Directory\Background\shell\customname' -Force
    

    Note:


    [1] Note that the Core part of the name does not refer to PowerShell Core (now renamed to PowerShell 7), the open-source, cross-platform PowerShell edition that succeeded Windows PowerShell; it simply denotes a module that is at the core of either edition.