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

PowerShell Where-Object语法错误:-Match参数需同时指定属性与值

问题解决:PowerShell Where-Object 语法错误

错误原因

你的Where-Object命令参数使用逻辑错误:-PipelineVariable是用来给管道对象定义别名的参数,不能直接和-Match运算符搭配使用。当使用-Match这类比较运算符时,必须明确指定要匹配的属性(通过-Property参数),或者使用脚本块写法,否则PowerShell会判定你缺少必要参数。

正确命令写法

写法一:用 -Property 指定匹配属性

$eventInitTerminate = Get-WinEvent -FilterHashtable @{LogName='Application';ProviderName='chromoting';StartTime=$initTime;EndTime=$crashOccurredTime;} -ErrorAction SilentlyContinue | Where-Object -Property Message -Match 'Channel'

写法二:脚本块写法(推荐,更灵活)

$eventInitTerminate = Get-WinEvent -FilterHashtable @{LogName='Application';ProviderName='chromoting';StartTime=$initTime;EndTime=$crashOccurredTime;} -ErrorAction SilentlyContinue | Where-Object { $_.Message -match 'Channel' }

补充说明

如果确实需要使用-PipelineVariable(比如后续管道要复用当前对象),正确用法示例:

$eventInitTerminate = Get-WinEvent -FilterHashtable @{LogName='Application';ProviderName='chromoting';StartTime=$initTime;EndTime=$crashOccurredTime;} -ErrorAction SilentlyContinue | Where-Object -PipelineVariable ev { $ev.Message -match 'Channel' }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 21:15:46