You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Get-CimInstance的Filter参数中使用OR子句?

正确实现Get-CimInstance多进程筛选的方法

你的问题出在把-or当成了PowerShell的独立参数,实际上-Filter参数需要接收完整的WQL查询字符串,逻辑运算符OR要写在这个字符串内部,而不是作为单独参数传递。

正确的命令写法如下:

Get-CimInstance -ClassName Win32_Process -Filter "Name LIKE 'powershell%' OR Name LIKE 'pwsh%'"

如果要精准匹配powershell_ise.exe,可以直接在Filter里追加条件:

Get-CimInstance -ClassName Win32_Process -Filter "Name LIKE 'powershell%' OR Name LIKE 'pwsh%' OR Name = 'powershell_ise.exe'"

为什么之前的写法报错

你之前的代码把-or作为Get-CimInstance的参数,但这个cmdlet并没有名为or的参数,所以会提示找不到匹配的参数。WQL筛选逻辑必须完全包含在-Filter的引号内,遵循WQL的语法规则。

另外也可以用PowerShell的管道筛选替代(如果不需要在CIM层面过滤的话):

$targetNames = 'powershell.exe', 'powershell_ise.exe', 'pwsh.exe'
Get-CimInstance -ClassName Win32_Process | Where-Object { $targetNames -contains $_.Name }

内容的提问来源于stack exchange,提问作者Matt Williamson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:52:32