New-PSDrive does not support credentials?

非 Y 不嫁゛ 提交于 2019-12-29 07:40:07

问题


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!


回答1:


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).




回答2:


If you still get the error after installing KB2819745 (powershell 4) then you might have forgotten Dotnet 4.5.

DotNet 4.5 is a requirement for WinRM 4 / Powershell 4, yet the msu installs without it.

This was the issue i was facing, after installing KB2819745 i still got the error. Install Dotnet 4.5 and then rerun KB2819745. Strangely it will reinstall when you installed dotnet, but without dotnet it says its already installed




回答3:


echo "pass"| net use \\server\share /user:domain\user

it is also working :)



来源:https://stackoverflow.com/questions/17036912/new-psdrive-does-not-support-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!