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.
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:Note:
The
Registrypart of the prefix is the provider name, as shown inGet-PSProvider's output.Hypothetically, multiple providers with the same name could be registered, in which case you can prefix the name with the implementing module name for disambiguation; in the case of the registry provider, this module-qualified prefix is
Microsoft.PowerShell.Core\Registry::[1] However, it's fair to assume that no third-party providers will choose a name that conflicts with the providers that ship with PowerShell, soRegistry::(orregistry::, case doesn't matter), should do.Note that the module-qualified provider name does show up in the prefix of the
.PSPathproperty that provider items, such as reported byGet-ItemandGet-ChildItem, are decorated with, e.g.:[1] Note that the
Corepart of the name does not refer to the PowerShell (Core) edition; it simply denotes a module that is at the core of either edition.