【发布时间】:2019-05-30 08:40:10
【问题描述】:
我正在尝试与不在域环境中的远程服务器建立连接。 在没有脚本的情况下在 PowerShell 控制台上单独运行 Set-Item 时,由于某种原因它不能在脚本上运行。
$passwd = convertto-securestring -String <Password> -AsPlainText -Force
$cred = New-Object -Typename System.Management.Automation.PSCredential -ArgumentList "developer", $passwd
$server = Read-Host -Prompt 'Input your server IP'
Set-Item wsman:\localhost\client\TrustedHosts -Value $server -Force
$session = new-pssession -computername $server -credential $cred
当我运行上面的代码时,我收到了消息
Set-Item : 无法将 'System.Object[]' 转换为类型 参数所需的“System.String”。不支持指定的方法。
【问题讨论】:
标签: string powershell