0

I know others have posted about this, but every thing i've tried so far hasn't worked. The issue i'm running into is that when I add brackets around my Where-Object statement, it turns the column that i'm trying to filter on into a function. Thus not allowing it to run.

$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

I'm hoping to be able to filter on both PropsView.version and Properties.OSType at the same time. At the moment I can do one or the other, but right when I try to add both I run into the error.

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.
4
  • 3
    You need to prefix the properties in the filter with$_.. Like this: ($_.PropsView.version -lt '5.5.0.447') -and ($_.Properties.OSType -ne 'Mac OS X') . Also, consider swapping your Select-Object and Where-Object calls as you are creating objects that you then through away (if they don't match the filter). Commented Jun 17, 2019 at 15:12
  • 1
    Try $_.'PropsView.version'. It will also help if you show the output of $AgentList | Format-List | Select -First 1 Commented Jun 17, 2019 at 15:13
  • @boxdog I attempted that earlier, and the issue i'm running into is that it no longer actually sorts the data and instead just pulls everything. Do I need to prefix the properties in the Select-Object clause as well? And thanks for the advice. Commented Jun 17, 2019 at 15:15
  • I figured it out, I was just making a simple mistake of not adding the single quotes after $_.. Thanks guys! Commented Jun 17, 2019 at 15:17

1 Answer 1

1
$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

Just needed to add the $_. and then single quotes around the column i'm sorting. It was the single quotes that I wasn't adding that messed me up. Thanks for the help everyone!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.