powershell 调用命令失败:WinRM无法完成该操作

wqlqzqxt  于 2023-02-23  发布在  Shell
关注(0)|答案(3)|浏览(264)

使用两台机器,一台本地机器和一台远程机器(地址标记为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
qqrboqgw

qqrboqgw1#

您是否已将远程设备添加到本地可信主机列表?如果没有,您可以通过

winrm s winrm/config/client '@{TrustedHosts="RemoteComputer"}'
iklwldmw

iklwldmw2#

您是否有到计算机的活动远程会话(如远程桌面)?
我的经验表明,这可能是Invoke-Command失败的唯一原因。

cuxqih21

cuxqih213#

确保您的网络连接配置文件应为专用。

下面是公开配置文件的原因。

在我的例子中,在将NetConnectionProfile从公共更改为私有后,它开始工作。我希望这对你有用。

相关问题