如何在 PowerShell 中停止进程的所有实例?


若要在 PowerShell 中停止运行进程的所有实例,Stop-Process 命令应运而生。例如,在以下示例中,我们有两个正在运行的 notepad.exe 进程实例。

命令

PS C:\WINDOWS\system32> Get-Process notepad

输出

PS C:\WINDOWS\system32> Get-Process notepad

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    228      13     3160      13448       0.14  15564   1 notepad
    228      14     3148      13668       0.17  22644   1 notepad

若要停止正在运行进程的所有实例,将使用以下命令。

Stop-Process -Name notepad

您还可以在管道中使用 Stop-Process 来结束进程。

Get-Process -Name notepad | Stop-Process

若要停止多个进程,请使用逗号 (,) 分隔不同的进程名称

Get-Process SkypeApp,notepad |Stop-Process -Confirm:$false

更新: 22-01-2020

2K+ 浏览量

开启你的 职业

完成课程以获得认证

开始学习
广告
© . All rights reserved.