Cannot add "-persist" to New-PSDrive - getting error "network resource type is not correct"
Update:
This problem has been fixed as of (at least) PowerShell 7.0.5 - however, it persists in Windows PowerShell (v5.1) and is unlikely to get fixed there.
A related problem that still exists as of v7.1 (the latest stable version as of this writing) is that using
-Persist
also results in misleading error messages under true error conditions:Thanks, dgm.- If the target host happens to be unreachable / not to be supporting CIFS, you also get
The network resource type is not correct
error. - If the host is reachable but the target directory doesn't exist, you get
The specified network resource or device is no longer available.
- By contrast, if you do not use
-Persist
, the error message is more sensible:The specified drive root "\\foo\bar" either does not exist, or it is not a folder.
(though it doesn't indicate which of the two error condition applies).
- If the target host happens to be unreachable / not to be supporting CIFS, you also get
[Windows PowerShell and PowerShell Core 6.x only] As you've discovered:
Don't specify drive root paths with a trailing \
, because doing so causes New-PSDrive
to fail with obscure error message New-PSDrive : The network resource type is not correct
when -Persist
is used:
# Trailing '\': only OK *without* -Persist.New-PSDrive -root \\foo\bar\ -name N -PSProvider filesystem# !! Breaks with -Persist:New-PSDrive -root \\foo\bar\ -name N -PSProvider filesystem# No trailing '\': OK both with and without -PersistNew-PSDrive -root \\foo\bar -name N -PSProvider filesystem
I've reported this unexpected behavior on GitHub, and a fix has been green-lighted for PowerShell Core, though it's unclear in what future version it will be available (written as of PowerShell Core 6.2.0-preview.1).