首页 > 解决方案 > 在 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.

标签: powershell

解决方案


$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

只需添加 $_. 然后在我正在排序的列周围加上单引号。是我没有添加的单引号让我感到困惑。感谢大家的帮助!


推荐阅读