powershell - Get-Process 到远程计算机不起作用,但 Invoke-Command 可以

标签 powershell powershell-remoting

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

我必须使用 Enable-PSRemoting -SkipNetworkProfileCheck 才能正常工作。我还必须将计算机添加到彼此的 TrustedHosts 列表中。

Get-Process -ComputerName VM01

将返回“无法连接到远程机器”。然而,
Invoke-Command -ComputerName VM01 -ScriptBlock {Get-Process}

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

最佳答案

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

关于powershell - Get-Process 到远程计算机不起作用,但 Invoke-Command 可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46176520/

相关文章:

windows - 是否可以只为 catch block 创建一个函数?

powershell - Powershell-使用.htm文件作为电子邮件正文

powershell - 如何使用 Powershell 跨卷移动文件/文件夹?

powershell - 将写入进度栏添加到脚本Powershell

eclipse - 从 Eclipse IDE 启动 PowerShell 脚本

.net - Powershell 'Start-Job` 与 'Start-Process'

用于 Powershell 远程脚本的 Android 客户端?

Powershell 远程处理的 Python 包装器

windows - Terraform azurerm_virtual_machine_extension错误 "extension operations are disallowed"

windows - 通过 PowerShell 使用路径组件创建注册表项