Skip to content

New-PSDrive fails with a UNC path with a trailing backslash when combined with -Persist #8242

@mklement0

Description

@mklement0

Without the -Persist switch, you can optionally specify the root path with a trailing \ - in other words: whether or not a trailing \ is present makes no difference.

If you add the -Persist switch (Windows-only, only with single-letter drive names), a path with a trailing \ causes an obscure error:

New-PSDrive : The network resource type is not correct

Note that successful creation of the drive (without -Persist) actually retains the trailing \, as reflected in the .Root property of the drive, but it seems to have to no ill effects.

Note: A separate problem is that trying to use -Persist on Unix-like platforms, where it is fundamentally unsupported, does not indicate that fact in its error message - see #8250

Steps to reproduce

On Windows:

New-PSDrive -root '\\foo\bar\' -name N  -PSProvider filesystem  -Persist

Expected behavior

Drive creation should succeed.

Actual behavior

The following error occurs:

New-PSDrive : The network resource type is not correct

Simply removing the trailing \ makes the problem go away.

Environment data

PowerShell Core 6.2.0-preview.1 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.165)
Windows PowerShell v5.1.17134.228 on Microsoft Windows 10 Pro (64-bit; Version 1803, OS Build: 17134.345)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions