powershell - 在 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)
我知道还有很多其他的东西,但是到目前为止我尝试过的所有东西都不起作用。谢谢您的帮助。
解决方案
是的,您必须使用 where-object 的脚本块版本。还要注意 -and 和 -or 在 powershell 中具有 EQUAL PRECEDENCE ,这在语言中是非常不寻常的。
推荐阅读
- excel - 无法分配字符串变量 VBA
- python - 使用 GitHub API 检查用户是否存在
- c# - 如何使用 streamwriter 更改文件写入的路径
- python - python html从具有td类型的表中抓取
- python - 以“优雅”的方式打印列表列表
- python - 自定义 Keras/TensorFlow 损失函数惩罚输出变化
- python - 当我尝试使用 pip install psycopg2 安装 psycopg2 时,出现此错误。我应该怎么办?
- mysql - 直接 SQL 而不是光标和循环
- java - 我如何从 recylerview 获取单个值
- python - 删除重复的列值并根据熊猫中的条件选择保留行