如何使用带有 Powershell 的 CMD 在另一台计算机上停止程序

问题描述

我想在卸载之前停止 pulse Secure 并使用 Powershell 安装更新版本

在计算机的 CMD 中,您可以输入以下内容来停止它:

"C:\Program Files (x86)\Common Files\pulse Secure\JamUI\pulse.exe" -stop

但我似乎无法从 Powershell 中阻止它。我尝试了几种不同的变体,但似乎无法理解。

$PC = (Read-Host "Enter Computer Name").toupper()
ICM $PC {& cmd.exe /c '"C:\Program Files (x86)\Common Files\pulse Secure\JamUI\pulse.exe" -stop'}

.

$PC = (Read-Host "Enter Computer Name").toupper()
$STOP = "C:\Program Files (x86)\Common Files\pulse Secure\JamUI\pulse.exe"
ICM $PC {& cmd.exe /c "$STOP -stop"}

第二个选项返回“-stop”不被识别为内部或外部命令...有什么建议或更好的方法来阻止它?

解决方法

invoke-command -ComputerName $pc -ScriptBlock {Stop-process -name Pulse -force}

做到了。