我正在使用下面的 powershell 脚本来执行
param([string]$Server,[string]$locusername,[string]$locpassword)
$password = '$locpassword' | ConvertTo-SecureString -asPlainText -Force
$username = $locusername
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
Run Code Online (Sandbox Code Playgroud)
我收到错误
无法将参数绑定到参数“String”,因为它为空。+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString]、ParameterBindingValidationException + ExcellentQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed、Microsoft.PowerShell.Commands.ConvertToSecureStringCommand
Clu*_*fin -2
使用双引号代替单引号,以进行字符串扩展
$password = "$locpassword" | ConvertTo-SecureString -asPlainText -Force
Run Code Online (Sandbox Code Playgroud)
完整代码:
param([string]$Server,[string]$locusername,[string]$locpassword)
$password = "$locpassword" | ConvertTo-SecureString -asPlainText -Force
$username = $locusername
$cred = New-Object System.Management.Automation.PSCredential($username,$password)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
28964 次 |
最近记录: |