powershell - 在 Where-Object 语句中添加多个子句
问题描述
我知道其他人已经发布了这个,但到目前为止我尝试过的每件事都没有奏效。我遇到的问题是,当我在 Where-Object 语句周围添加括号时,它会将我试图过滤的列变成一个函数。因此不允许它运行。
$AgentList | Select-Object Leaf.NodeName, Properties.OSType, PropsView.version, BranchNode.Node | Where-Object{ (PropsView.version -lt '5.5.0.447') -and (Properties.OSType -ne 'Mac OS X')} | Sort-Object -Property EPOBranchNode.NodeTextPath2 -Descending
我希望能够同时过滤 PropsView.version 和 Properties.OSType。目前我可以做一个或另一个,但是当我尝试添加两者时,我遇到了错误。
The term 'PropsView.version' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
解决方案
$AgentList | Select-Object Leaf.NodeName, Properties.OSType, PropsView.version, BranchNode.Node | Where-Object{ ($_.'PropsView.version' -lt '5.5.0.447') -and ($_.'Properties.OSType' -ne 'Mac OS X')} | Sort-Object -Property EPOBranchNode.NodeTextPath2 -Descending
只需添加 $_. 然后在我正在排序的列周围加上单引号。是我没有添加的单引号让我感到困惑。感谢大家的帮助!
推荐阅读
- python - 尝试使用熊猫对 MultiIndex 数据帧中的索引进行重新采样
- apache-iotdb - IoTDB:插入记录时发生异常。java.lang.ArrayIndexOutOfBoundsException
- java - 如何从数组中获取随机数组?
- mysql - 你将如何在 SQL 上解决这个问题?
- javascript - Vue.js 中父级数据更改时如何重新渲染内部组件
- python - Streamlit 如何在一行中显示按钮
- docker - 尝试在 wsl2 windows10 上拉 hello-world 图像时超时
- spring-boot - DMN-02003 无法转换决策原因:org.xml.sax.SAXException:cvc-elt.1.a:找不到元素“定义”的声明
- java - Java Servlet 上下文和 servlet 路径问题通过链接重定向
- flutter - Flutter - 如何用鼠标指针绘制矩形并获取坐标