gpt4 book ai didi

arrays - PowerShell 杀死多个进程

转载 作者:行者123 更新时间:2023-12-03 18:18:45 32 4
gpt4 key购买 nike

我正在尝试通过 PS 完成以下操作,但在获取所需内容时遇到问题。我尝试了许多不同的格式来编写这个脚本,这是我认为最接近的。

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

$softwarelist = 'chrome|firefox|iexplore|opera'
获取进程|
Where-Object {$_.ProcessName -eq $softwarelist} |
停止进程-力

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

1..50 | % {记事本;计算}

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

% { $_.Terminate() }

谢谢你的帮助!

最佳答案

您的 $softwarelist变量看起来像一个正则表达式,但在你的 Where-Object 中条件,您正在使用 -eq运算符(operator)。我想你想要 -match运算符(operator):

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

您还可以将多个进程传递给 Get-Process ,例如
Get-Process -Name 'chrome','firefox','iexplore','opera' | Stop-Process -Force

关于arrays - PowerShell 杀死多个进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25558189/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com