Powershell小技巧之复合筛选
程序员文章站
2022-11-15 17:30:07
当你分析文本日志或筛选不通类型的信息时,你通常要使用 where-object。这里有一个通用脚本来说明复合筛选:
# logical and filter fo...
当你分析文本日志或筛选不通类型的信息时,你通常要使用 where-object。这里有一个通用脚本来说明复合筛选:
# logical and filter for all keywords get-content -path c:\windows\windowsupdate.log | where-object { $_ -like '*successfully installed*' } | where-object { $_ -like '*framework*' } | out-gridview # above example can also be written in one line # by using the -and operator # the resulting code is not faster, though, just harder to read get-content -path c:\windows\windowsupdate.log | where-object { ($_ -like '*successfully installed*') -and ($_ -like '*framework*') } | out-gridview # logical -or (either condition is met) can only be applied in one line get-content -path c:\windows\windowsupdate.log | where-object { ($_ -like '*successfully installed*') -or ($_ -like '*framework*') } | out-gridview