Skip to content

Windows: PowerShell reports a broken subst.exe drive as nonexistent #20894

Open

Description

Prerequisites

Steps to reproduce

Related:

However, the issue at hand isn't specific to v7.4.0 and dates back to Windows PowerShell.

# On Windows

# Establish a T: drive pointing to a temp. directory
subst T: /d 2>$null
subst T: ($dir = New-Item -Type Directory -Force "$env:TEMP:\$PID")
# Remove the temp. directory, which leaves T: in a broken state.
$dir | Remove-Item

# Try to get information about T:, which should still be possible
[System.IO.DriveInfo]::new('T')
Get-PSDrive T

Expected behavior

Name               : T:\
IsReady            : False
RootDirectory      : T:\
DriveType          : NoRootDirectory
DriveFormat        :
AvailableFreeSpace :
TotalFreeSpace     :
TotalSize          :
VolumeLabel        :

CurrentLocation        :
Name                   : T
Provider               : Microsoft.PowerShell.Core\FileSystem
Root                   : T:\
Description            :
MaximumSize            :
Credential             : System.Management.Automation.PSCredential
DisplayRoot            :
VolumeSeparatedByColon : True
Used                   : 
Free                   :

Actual behavior

Name               : T:\
IsReady            : False
RootDirectory      : T:\
DriveType          : NoRootDirectory
DriveFormat        :
AvailableFreeSpace :
TotalFreeSpace     :
TotalSize          :
VolumeLabel        :

Get-PSDrive: 
Line |
   6 |  Get-PSDrive T
     |  ~~~~~~~~~~~~~
     | Cannot find drive. A drive with the name 'T' does not exist.

That is, PowerShell now thinks the drive no longer exists, even though it still does, albeit in a broken state.

cmd /c dir T: doesn't complain about a missing drive, but a missing file (presumably the generic 0x2 system error that indicates a non-existent file or directory).

Error details

No response

Environment data

PowerShell 7.4.0 on Windows 11 22H2

Visuals

No response

Activity

  1. SteveL-MSFT commented on Dec 11, 2023

    @SteveL-MSFT
    Member

    I looked into this and what's happening is that https://learn.microsoft.com/en-us/dotnet/api/system.io.driveinfo.getdrives?view=net-8.0 doesn't return the broken drive so PowerShell has no knowledge of it. You should open an issue in dotnet/runtime to maybe have an overload of that method with flags if you think this is a useful scenario to get that info.

    Retrieves the drive names of all logical drives on a computer.
  2. added
    Resolution-ExternalThe issue is caused by external component(s).
    and removed
    Needs-TriageThe issue is new and needs to be triaged by a work group.
    on Dec 11, 2023
  3. mklement0 commented on Dec 11, 2023

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT), from what I can tell, this .NET API does report the broken drive.

    In the repro above, if you replace [System.IO.DriveInfo]::new('T') with [System.IO.DriveInfo]::GetDrives(), you'll see that T: is still there after the target dir. was removed.

  4. iSazonov commented on Dec 11, 2023

    @iSazonov
    Collaborator

    I wonder why do we need the broken drive? PowerShell does the job better.

  5. mklement0 commented on Dec 11, 2023

    @mklement0
    ContributorAuthor

    Because users may want to know the difference between whether a drive exists and just happens to be - possibly temporarily - unavailable (e.g. #20861, though that particular case may be an outright bug) - and wether no such drive is defined.

    It is inappropriate to ignore the existence of a drive just because it happens to be in a broken state - report the drive, and report an appropriate error on trying to access it (along the lines of "drive T: is not accessible")

    In other words: Please remove the Resolution-External label and keep this issue open.

  6. mklement0 commented on Dec 11, 2023

    @mklement0
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-FileSystem-Providerspecific to the FileSystem providerNeeds-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions