In a PowerShell session, I can change a file system drive with C:
, D:
etc:
PS: C:\> d:
PS: D:\> c:
PS: C:\>
However, trying the same thing with a registry drive (HKCU:
) does not work:
PS: C:\> hkcu:
hkcu: : The term 'hkcu:' is not recognized as the name of a cmdlet, function, script file, or operable program. ....
However, I can change drive using set-location
(cd
):
PS: C:\> cd hkcu:
PS: HKCU:\>
I am surprised about this behavor which I feel is inconsistent and would like to know why this is or what's going on behind the scenes.
CodePudding user response:
The filesystem drive names (C:
, D:
, etc.) are explicitly defined as functions; the registry "drives" (HKCU:
etc.) are not. You can enable the same behavior for the registry "drives" by defining functions for them in the same way:
function HKCU: {
Set-Location $MyInvocation.MyCommand.Name
}