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)
Without the
-Persistswitch, 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
-Persistswitch (Windows-only, only with single-letter drive names), a path with a trailing\causes an obscure error:Note that successful creation of the drive (without
-Persist) actually retains the trailing\, as reflected in the.Rootproperty of the drive, but it seems to have to no ill effects.Note: A separate problem is that trying to use
-Persiston Unix-like platforms, where it is fundamentally unsupported, does not indicate that fact in its error message - see #8250Steps to reproduce
On Windows:
Expected behavior
Drive creation should succeed.
Actual behavior
The following error occurs:
Simply removing the trailing
\makes the problem go away.Environment data