PowerShell's ~ can be counterintuitive, as it's relative to the current location's path and defined by a property of the current location's PSProvider:
PS C:\> Get-PSDrive C,S,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem C:\Users\jtm
S FileSystem C:\Users\jtm
HKLM Registry
PS C:\Users\jtm> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem C:\Users\jtm
S FileSystem C:\Users\jtm
HKCU Registry
HKLM Registry
PS C:\Users\jtm> cd HKLM:
PS HKLM:\> cd ~
Set-Location: Home location for this provider is not set. To set the home location, call "(get-psprovider 'Registry').Home = 'path'".
PS HKLM:\> (Get-Location).Provider.Home = 'C:\Program Files\Microsoft Office'
PS HKLM:\> cd ~
PS C:\Program Files\Microsoft Office> (Get-Location).Provider.Home = 'HKLM:\SYSTEM\CurrentControlSet'
PS C:\Program Files\Microsoft Office> cd S:
PS S:\> cd ~
PS HKLM:\SYSTEM\CurrentControlSet> (Get-Location).Provider.Home = '..'
PS HKLM:\SYSTEM\CurrentControlSet> cd ~
PS HKLM:\SYSTEM> cd ~
PS HKLM:\> Get-PSDrive C,S,HKCU,HKLM | select Name,{$_.Provider.Name},{$_.Provider.Home}
Name $_.Provider.Name $_.Provider.Home
---- ---------------- ----------------
C FileSystem HKLM:\SYSTEM\CurrentControlSet
S FileSystem HKLM:\SYSTEM\CurrentControlSet
HKCU Registry ..
HKLM Registry ..
PS HKLM:\>
Even in the Unix world, it's shell-specific, but most shells tend to expand ~ out to $HOME (which in turn gets expanded to the actual path). They also have complicated rules about when ~ characters are expanded or not.
sedatk|2 years ago
jasomill|2 years ago
HeckFeck|2 years ago
chungy|2 years ago