首页 > 解决方案 > 在 Powershell 的 WHERE 子句中添加多个 -and 和 -or 语句

问题描述

我目前正在使用 Powershell,并且正在尝试对从另一个系统中提取的变量中的数据进行排序。目前我正在尝试在 -eq 符号之后使用一个 -and 语句和 -or 语句。所以我想知道在 where 语句中创建语法的正确方法是什么。

$DLPList | Select Node.NodeName, Properties.OSType, PropsView.version, Node.NodeTextPath2 | where PropsView.version -ne '1.4.706.172' -and (Properties.OSType -eq $win7 -or $win8 -or $win81 -or $win10)

我知道还有很多其他的东西,但是到目前为止我尝试过的所有东西都不起作用。谢谢您的帮助。

标签: powershell

解决方案


是的,您必须使用 where-object 的脚本块版本。还要注意 -and 和 -or 在 powershell 中具有 EQUAL PRECEDENCE ,这在语言中是非常不寻常的。


推荐阅读