PowerShell杀死多个进程

las*_*uce 2 arrays powershell process terminate

我试图通过PS完成以下内容并且遇到问题得到我需要的东西.我已经尝试了许多不同的格式来编写这个脚本,这是我认为最接近的.

我运行以下并没有错误,但也没有结果.

$softwarelist = 'chrome|firefox|iexplore|opera'
get-process |
Where-Object {$_.ProcessName -eq $softwarelist} |
stop-process -force

这是我尝试的另一个例子,但是这个例子并没有终止我提供的所有过程(W8.1中的IE).

1..50 | % {notepad;calc}

$null = Get-WmiObject win32_process -Filter "name = 'notepad.exe' OR name = 'calc.exe'" |

% { $_.Terminate() }

谢谢你的帮助!

Aar*_*sen 10

您的$softwarelist变量看起来像正则表达式,但在您的Where-Object情况下,您正在使用-eq运算符.我想你想要-match运营商:

$softwarelist = 'chrome|firefox|iexplore|opera'
get-process |
    Where-Object {$_.ProcessName -match $softwarelist} |
    stop-process -force
Run Code Online (Sandbox Code Playgroud)

您还可以将多个流程传递给Get-Process,例如

Get-Process -Name 'chrome','firefox','iexplore','opera' | Stop-Process -Force
Run Code Online (Sandbox Code Playgroud)