powershell - 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
- ... s” -Credential $mycreds -Persist
-
~~~~~~~~
- CategoryInfo : InvalidData: (:) [New-PSDrive], ParameterBindingArgumentTransformationException
- FullyQualifiedErrorId : ParameterArgumentTransformationError,Microsoft.PowerShell.Commands.NewPSDriveCommand
解决方案
推荐阅读
- gradle - 分发 4.10.2 后的 gradle 问题
- python - 如何在python中显示ros标记?
- http - 为什么服务器错误代码从 1xx 而不是 0xx 开始?
- javascript - 通过导入类方法而不需要整个类来制作模块化 javascript 库
- python - 获取特定模式的正则表达式
- spring - 从 Spring Boot Actuator 获取系统信息
- kivy - 用 Kivy 语言在另一个图形上绘制图形
- .net - 内存是如何分配和释放的?
- c# - 如何修复 SqlError :从字符串转换日期和/或时间时失败。EF二进制表达式?
- python - Python While 循环中的动态变量