远程计算机的Get-Process不起作用,但是Invoke-Command起作用

时间:2022-06-14 21:48:32

I have a 2 servers running Windows Server 2012 R2. One of them is hosting a virtual machine running Windows 7 32-bit, and I am trying to use the other server to view the currently running processes of the virtual machine.

我有两台服务器运行Windows Server 2012 R2。其中之一是托管运行32位Windows 7的虚拟机,我正在尝试使用另一个服务器查看虚拟机当前运行的进程。

I had to use Enable-PSRemoting -SkipNetworkProfileCheck for anything to work. I also had to add the computers to each others TrustedHosts lists.

我必须使用Enable-PSRemoting -SkipNetworkProfileCheck检查任何工作。我还必须将计算机添加到彼此托管列表中。

Get-Process -ComputerName VM01

will return a "Couldn't connect to remote machine". However,

将返回一个“无法连接到远程机器”。然而,

Invoke-Command -ComputerName VM01 -ScriptBlock {Get-Process}

works just fine. What is the difference between using Invoke-Command and using the Get-Process with a ComputerName argument? In case it is important, I can also use Enter-PSSession without any problems

工作得很好。使用Invoke-Command和使用带有ComputerName参数的Get-Process有什么区别?如果重要的话,我也可以使用Enter-PSSession,没有任何问题

2 个解决方案

#1


6  

Get-Process probably uses the DCOM/RPC remoting protocol instead of Windows Remote Management (WinRM), which is what PowerShell Remoting (eg. Invoke-Command) uses. If you have a firewall blocking DCOM/RPC, then I could see how Get-Process with the -ComputerName parameter would fail. With PowerShell Remoting (via WinRM), all you need to do is open up TCP 5985 (HTTP) and TCP 5986 (HTTPS, optional).

Get-Process可能使用DCOM/RPC远程处理协议,而不是Windows远程管理(WinRM),这就是PowerShell远程处理(例如)。Invoke-Command)使用。如果您有防火墙阻止DCOM/RPC,那么我可以看到使用-ComputerName参数的Get-Process如何失败。使用PowerShell Remoting(通过WinRM),您只需打开TCP 5985 (HTTP)和TCP 5986 (HTTPS,可选)。

#2


3  

I ran across this error my self today, the solution in my case (I already had enabled port 5985) the problem occurred because of my firewall blocked port 445 (on the target).

我今天遇到了这个错误,我的解决方案(我已经启用了端口5985)由于防火墙阻塞了端口445(在目标上),出现了问题。

As soon as this port was enabled I was able to use,

一旦这个端口被启用,我就可以使用,

Get-Process -ComputerName dc01

and

Get-Service -ComputerName dc01

However I do recommend you read this page: https://www.grc.com/port_445.htm as it seems that some security issues may appear upon allowing this port toward the Internet.

不过,我建议您阅读这一页:https://www.grc.com/port_445.htm,因为似乎在允许这个端口进入Internet时可能出现一些安全问题。

My symptoms was exactly as OP descripes...

我的症状和OP描述的完全一样……

#1


6  

Get-Process probably uses the DCOM/RPC remoting protocol instead of Windows Remote Management (WinRM), which is what PowerShell Remoting (eg. Invoke-Command) uses. If you have a firewall blocking DCOM/RPC, then I could see how Get-Process with the -ComputerName parameter would fail. With PowerShell Remoting (via WinRM), all you need to do is open up TCP 5985 (HTTP) and TCP 5986 (HTTPS, optional).

Get-Process可能使用DCOM/RPC远程处理协议,而不是Windows远程管理(WinRM),这就是PowerShell远程处理(例如)。Invoke-Command)使用。如果您有防火墙阻止DCOM/RPC,那么我可以看到使用-ComputerName参数的Get-Process如何失败。使用PowerShell Remoting(通过WinRM),您只需打开TCP 5985 (HTTP)和TCP 5986 (HTTPS,可选)。

#2


3  

I ran across this error my self today, the solution in my case (I already had enabled port 5985) the problem occurred because of my firewall blocked port 445 (on the target).

我今天遇到了这个错误,我的解决方案(我已经启用了端口5985)由于防火墙阻塞了端口445(在目标上),出现了问题。

As soon as this port was enabled I was able to use,

一旦这个端口被启用,我就可以使用,

Get-Process -ComputerName dc01

and

Get-Service -ComputerName dc01

However I do recommend you read this page: https://www.grc.com/port_445.htm as it seems that some security issues may appear upon allowing this port toward the Internet.

不过,我建议您阅读这一页:https://www.grc.com/port_445.htm,因为似乎在允许这个端口进入Internet时可能出现一些安全问题。

My symptoms was exactly as OP descripes...

我的症状和OP描述的完全一样……