Powershell: New-PSDrive fails with a UNC path with a trailing backslash when combined with -Persist

Created on 12 Nov 2018  路  7Comments  路  Source: PowerShell/PowerShell

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)
Area-Cmdlets-Management Issue-Discussion Resolution-Fixed Up-for-Grabs

Most helpful comment

Since -Persist as it's designed today is really net use /persistent:yes so only works with UNC paths, it seems ok to just trim the trailing slash

All 7 comments

@mklement0

Interesting!! I got a different error in all of my systems: Linux and Windows, In either PowerShell Core GA 6.1.0 and Preview 6.2.0-Preview.1.

... To use the Persist switch parameter, the drive name must be supported by the operating system (for example, drive letters A-Z).
At line:1 char:1
+ new-psdrive -root "\\xxxxx\xxxx" -name Shared1 -PSProvide ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Shared1:PSDriveInfo) [New-PSDrive], InvalidOperationException
+ FullyQualifiedErrorId : DriveNameNotSupportedForPersistence,Microsoft.PowerShell.Commands.NewPSDriveCommand

psdrive_01_2018-11-12_19-17-01
psdrive_02_2018-11-12_19-17-01
psdrive_03_2018-11-12_19-17-01
psdrive_04_2018-11-12_19-17-01

Definitely! Something with the "-Persist" parameter.
:)

@MaximoTrinidad: You've hit an unrelated problem, namely that -Persist is fundamentally unsupported on Unix-like platforms, which the error message does not indicate - see #8250

I've also updated the initial post to make that clearer.

Since -Persist as it's designed today is really net use /persistent:yes so only works with UNC paths, it seems ok to just trim the trailing slash

Thanks @SteveL-MSFT and @mklement0!
:)

I found solution for me:

whats the fix for this im still getting the issue.

@alextovey I see the problem neither in v7.0 nor the current preview (3); note that only critical fixes are back-ported to _Windows PowerShell_.

Was this page helpful?
0 / 5 - 0 ratings