首页 > 解决方案 > New-PSDrive:无法处理参数“凭据”的参数转换。用户名

问题描述

即使我使用 Get-Credential cmdlet 直接输入用户/密码或如下所示的 NetworkCredital,我也会收到无法无错误处理凭据。这是我的方法 - 首先我将加密的密码存储在一个单独的保险库文件中。然后运行此代码以执行网络共享映射:

$vault = 'C:\pwd.txt'

# retrieve the password.
$securestring = convertto-securestring -string (get-content $vault)
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securestring)
$passwsord = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

$mycreds = New-Object System.Net.NetworkCredential("$User", "$passwsord"); 

New-PSDrive -Name X -PSProvider FileSystem -Root “\\server\share” -Credential $mycreds -Persist

这是错误--Persist New-PSDrive:无法处理参数“凭据”上的参数转换。用户名在行:18 字符:119

标签: powershell

解决方案


推荐阅读