You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot use mapped network drive below drive h: #20861
Use subst to create a mapped network drive below drive h: (I tested from e: to g:), then attempt to set-location to the new drive.
I attempted to map to my Box drive
subst e: c:\users\xxxxxx\Box\Files
e:
I have regressed to v7.3.10 as this works fine.
Expected behavior
In PowerShell v7.3.10 this works and the location is set as expected:PS E:\>
Actual behavior
PS C:\> subst e: "C:\Users\xxxxxx\Box\Files"PS C:\> e:Set-Location: Cannot find drive. A drive with the name 'E' does not exist
Error details
Set-Location: Cannot find drive. A drive with the name 'E' does not exist
Just a data point: I cannot repro the problem on my Windows 11 Pro 22H2 machine.
Does running subst.exe without arguments list an E: drive. Does Get-PSDrive -PSProvider FileSystem reveal anything unusual?
Yes, subst on its own will list the e: drive.
No, Get-PSDrive -PSProvider FileSystem does not list the e: drive.
But [System.IO.DriveInfo]::getdrives() does list the e: drive.
The other issue with PS not recognising the drive is that when you start PS, it gives an error: Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failed
Also important to note that the subst drive location needs to be a network location, a local location, e.g. c:\Windows works ok. For me it is the local Box drive which identifies as 'Network'.
So it isn't about specific driver letters, but about the specific nature of the target directory, and it is somehow related to the target directory - though seemingly a local path - being a network path instead.
The question is what specific mechanism is used in the latter case; I do not see the problem when using subst with a network share explicitly (whether directly via a UNC path or indirectly via a regularly mapped drive).
Does Get-Item $HOME\Box | Format-List * reveal the specific NTFS reparse-point technology used (look for LinkType, LinkTarget and Attributes)?
So now we know that in your case it is an NTFS junction that points to a volume by GUID.
While I'm not sure how that is established, I have been able to reproduce one problem - which is at least part of the puzzle:
If the target of a subst.exe-established drive is removed or - presumably - unavailable, PowerShell inappropriately pretends that it doesn't even exist - irrespective of whether the target is a regular directory or an NTFS reparse point.
So, when you see the problem, is $HOME\Box actually accessible, with cmd /c dir $HOME\Box or Get-ChildItem $HOME\Box?
Thanks Michael Klement (@mklement0).
Yes, within PS 7.4.0, both of these commands work and list the directory contents.
The subst'd drive works fine within Windows, just PS is not able to use it in this version.
Activity
DougChandler commentedon Dec 7, 2023
With v7.4.0, using subst with a drive of h: or above also works.
mklement0 commentedon Dec 7, 2023
Just a data point: I cannot repro the problem on my Windows 11 Pro 22H2 machine.
Does running
subst.exewithout arguments list anE:drive. DoesGet-PSDrive -PSProvider FileSystemreveal anything unusual?DougChandler commentedon Dec 8, 2023
Yes,
subston its own will list the e: drive.No,
Get-PSDrive -PSProvider FileSystemdoes not list the e: drive.But
[System.IO.DriveInfo]::getdrives()does list the e: drive.The other issue with PS not recognising the drive is that when you start PS, it gives an error:
Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem' provider failedAlso important to note that the subst drive location needs to be a network location, a local location, e.g. c:\Windows works ok. For me it is the local Box drive which identifies as 'Network'.
DougChandler commentedon Dec 8, 2023
So Box Drive maps to
c:\Users\<username>\Box. There are two differences between:Drive f: will be accessible to PS, drive e: is not.
Running
[System.IO.DriveInfo]::getdrives()reveals that:One of these two things must be causing the issue in PS 7.4.0
mklement0 commentedon Dec 8, 2023
So it isn't about specific driver letters, but about the specific nature of the target directory, and it is somehow related to the target directory - though seemingly a local path - being a network path instead.
The question is what specific mechanism is used in the latter case; I do not see the problem when using
substwith a network share explicitly (whether directly via a UNC path or indirectly via a regularly mapped drive).Does
Get-Item $HOME\Box | Format-List *reveal the specific NTFS reparse-point technology used (look forLinkType,LinkTargetandAttributes)?DougChandler commentedon Dec 9, 2023
This is the result of the cmdLet (on PS v7.3.10)
Get-Item $HOME\Box | Format-List *(redacted):mklement0 commentedon Dec 9, 2023
Thanks, Doug Chandler (@DougChandler).
So now we know that in your case it is an NTFS junction that points to a volume by GUID.
While I'm not sure how that is established, I have been able to reproduce one problem - which is at least part of the puzzle:
If the target of a
subst.exe-established drive is removed or - presumably - unavailable, PowerShell inappropriately pretends that it doesn't even exist - irrespective of whether the target is a regular directory or an NTFS reparse point.So, when you see the problem, is
$HOME\Boxactually accessible, withcmd /c dir $HOME\BoxorGet-ChildItem $HOME\Box?DougChandler commentedon Dec 11, 2023
Thanks Michael Klement (@mklement0).
Yes, within PS 7.4.0, both of these commands work and list the directory contents.
The subst'd drive works fine within Windows, just PS is not able to use it in this version.
DougChandler commentedon Jan 24, 2024
It also works correctly as expected in PS v7.3.11, so appears it was introduced in 7.4.0.