New-PSDrive does not support credentials?

BlueChippy picture BlueChippy · Jun 11, 2013 · Viewed 15k times · Source

I am trying to map a drive in PowerShell 2.0 and getting this error?

New-PSDrive –Name ftp –PSProvider FileSystem –Root “\\server\folder” -Credential $credential
The provider does not support the use of credentials. Perform the operation again without specifying credentials.

However, Get-Help New-PSDrive shows -Credential as a valid option?

Is this a version issue in PS? Is there an alternative way to do the same...I would prefer to keep this within PS (since the drive is PS only then) and not drop out to NET USE - NET USE /d but needs must!

Answer

alroc picture alroc · Jun 11, 2013

It's a bug in PowerShell 2.0

Workaround from the above link:

$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("u:", "\\server\share", $false, "domain\user", "password")

Supposedly fixed in 3.0 (I haven't tested it myself).