使用2台计算机,本地和远程(地址标记为remoteAddress
),我试图在本地计算机上运行它:
Invoke-Command -ComputerName remoteAddress -ScriptBlock { dir c:\ }
但是我收到了这个错误:
[remoteAddress] Connecting to remote server remoteAddress failed with the following error message : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (remoteAddress:String) [], PSRemotingTransportException + FullyQualifiedErrorId : WinRMOperationTimeout,PSSessionStateBroken
我跟着修复了类似的情况。我检查了什么:
Ping到远程地址成功。
在两台机器上Enable-PSRemoting -Force
返回
WinRM is already set up to receive requests on this computer. WinRM is already set up for remote management on this computer.
Set-WSManQuickConfig
上的返回
WinRM is already set up to receive requests on this computer. WinRM is already set up for remote management on this computer.
但是,我仍然试图连接到远程计算机时遇到此错误。
我从本地计算机上运行了test-wsman -ComputerName _remote-machine_ -Port 5985
而且我收到了这个错误:
test-wsman : WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. At line:1 char:1 + test-wsman -ComputerName _remote_ -Port 5985 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (_remote-machine_:String) [Test-WSMan], InvalidOperationExcept ion + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.TestWSManCommand
答案 0 :(得分:0)
您是否将遥控器添加到本地可信主机列表?如果没有,您可以通过
添加它们winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'
答案 1 :(得分:0)
您是否有到计算机的活动远程会话,例如“远程桌面”?
我经历过,这可能是Invoke-Command失败的唯一原因。