Powershell停止远程服务器上的多个应用程序和进程

Powershell停止远程服务器上的多个应用程序和进程,powershell,process,remote-server,Powershell,Process,Remote Server,我正在尝试编写powershell脚本来停止远程服务器上的多个进程。最好的方法是什么?我应该创建powershell会话吗?使用invoke命令或只使用get wmiobject?我的运气在win32_process terminate()方法中发挥得最好,就像您所做的一样。我的运气在win32_process terminate()方法中发挥得最好,就像您所做的一样。 Function StopApplication{ Param( [Parameter(Mandatory=$tru

我正在尝试编写powershell脚本来停止远程服务器上的多个进程。最好的方法是什么?我应该创建powershell会话吗?使用invoke命令或只使用get wmiobject?

我的运气在win32_process terminate()方法中发挥得最好,就像您所做的一样。我的运气在win32_process terminate()方法中发挥得最好,就像您所做的一样。
Function StopApplication{

Param(
    [Parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]
    [string[]] $Servers,
    [Parameter(Mandatory=$true, ParameterSetName="ServiceNames")]
    [string[]] $ServiceNames,
    [Parameter()]
    [PSCredential] $Cred
)     
       foreach ($server in $Servers)
      {

     $stop = Get-WmiObject -Class Win32_process -ComputerName $Server | Where-Object {$_.ProcessName -match $ServiceName}
     $stop.terminate()
       }
}