使用powershell

时间:2018-05-03 13:03:21

标签: powershell winrm

我编写了powershell脚本,它连接到远程服务器并执行批处理文件

$password = ConvertTo-SecureString "pwd" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("user", $password )
Invoke-Command -ComputerName 10.10.10.10 -credential $cred -ErrorAction Stop -ScriptBlock {Invoke-Expression -Command:"cmd.exe /c 'C:\batchfile.bat'"}

但是我收到了错误:

 [‎10.10.10.10]Error while connecting to the server:  The WinRM client
 cannot process the request. Default authentication may be used with an
 IP address under the following conditions: the transport is HTTPS or
 the destination is in the TrustedHosts list, and   explicit
 credentials are provided. Use winrm.cmd to configure TrustedHosts.
 Note that computers in the TrustedHosts list might not be
 authenticated. For more information on how to set TrustedHosts run

 the   following command: winrm help config. For more information, see
     the about_Remote_Troubleshooting Help topic  At line:1 char:1
     + Invoke-Command -ComputerName 10.10.10.10 -credential $cred -ErrorAct ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
     + CategoryInfo          : OpenError: (10.10.10.10:String) [], PSRemotingTransportException
        + FullyQualifiedErrorId : CannotUseIPAddress,PSSessionStateBroken

我卡住了。请帮我解决这个问题。

我已尝试将名称添加到可信主机

0 个答案:

没有答案