i think i found a bug in PS.
i create a new subst'ed drive letter:
C:\> subst k: c:\test
C:\> subst
K:\: => c:\test
but PS tells:
PS C:\> get-item 'K:\' | Format-list | Out-String
Directory:
Name : K:\
Mode : d-----
LinkType :
Target : {K:\test}
as you see, the drive letter in target is wrong. how it comes?
my windows version:
Windows 10 Enterprise
Version 1809
OS Build 17763.1457
my PS version:
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.1432
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1432
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
how to get the correct target with ps?
many thanks
I agree that it is a bug, but:
No symbolic link or other NTFS reparse point (such as a junction) is involved in your code.
As such, the
.Targetproperty - which reports a reparse point's target - should not even be filled in; that is the actual bug, which longer exists in PowerShell [Core] v6+.Thus, in order to weed out such false
.Targetvalues, you can filter files by their.LinkTypeproperty instead:Separately, if you're looking for a way to translate paths based on substituted drives to their underlying physical paths:
Unfortunately, neither
Convert-PathnorGet-PSDriveseem to be aware of substituted drives (created withsubst.exe) - not even in PowerShell 7.0 - so you'll have to roll your own translation command:The above should return
C:\test\in your case.Note: Due to use of
Convert-Path, the above only works with existing paths; making it support nonexistent paths requires substantially more work (see below).Note that longstanding GitHub feature request #2993 asks for enhancing
Convert-Pathto also work with nonexistent paths.In the interim, here's advanced function
Convert-PathExto fill the gap.Once it is defined, you could do the following instead: