过滤不包含3个字符串的文件

时间:2017-02-08 10:48:07

标签: powershell

gci -r | Where-Object {
    !($_ | Select-String "BGM+795" -Quiet) -and
    !($_ | Select-String "BGM+227" -Quiet) -and
    !($_ | Select-String "BGM+781" -Quiet)
}

这就是我现在所拥有的。所有文件都出现了。

只使用其中一个“过滤器”工作正常,但我希望能够同时过滤多个。

有什么建议吗?

2 个答案:

答案 0 :(得分:0)

Select-String支持-Exclude参数(字符串数组)。 因此你可以写:

gci -r | Where-Object { $_ | sls -Exclude "BGM+795", "BGM+227", "BGM+781"}

希望对你有用。

答案 1 :(得分:0)

Get-ChildItem -Recurse | Where-Object { !($_ | Select-String -Pattern "(BGM\+227|BGM\+781|BGM\+795)") }

这就是诀窍。

Andreas的答案对我失败了:SLS不是一个已知的cmdlet。