我已经编写了连接到远程服务器并执行批处理文件的 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
我被困。请在这个问题上帮助我。
我也尝试将名称添加到受信任的主机