Question
Normalize registry path in PowerShell
There are several ways to reference a registry key in PowerShell:
- Using a builtin PSDrive, such as HKCU or HKLM, for example
HKLM:\SOFTWARE\Wow6432Node
. - Using a user-created PSDrive, such as HKCR for
HKEY_CLASSES_ROOT
. - Using the Registry:: provider:
Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
. - Maybe some other ways I'm not aware of.
Given a string in one of the above formats, how can I get a "normalized" registry key path (with the hive part expanded, HKCU => HKEY_CURRENT_USER etc) efficiently? Is there a way to do it without messing with regular expressions?