grisha
grisha

Reputation: 399

Filtering in Powershell

I have an array of objects called $listy. I am looking for object for which property $_.WorkflowAssociations.Count is greater than 0.

When I select that property I can see that several objects fulfill my criteria:

$listy | select title, workflowassociations.count

However when I use where: $listy | where {$_.WorkflowAssociations.Count -gt 0} none of the objects are listed: enter image description here

I have the same issue with $_.Views.Count property. Other numeric properties seem to filter without issues. Is it because of the point (.)? Why? The property is called exactly Views.Count: enter image description here

Upvotes: 0

Views: 291

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200193

As @EtanReisner already pointed out in the comments to your question: if you have a property name containing a dot (like WorkflowAssociations.Count) you must put the name in quotes when trying to access it via dot notation:

$listy | Where-Object { $_.'WorkflowAssociations.Count' -gt 0 }

If you don't, the term $_.WorkflowAssociations.Count will be interpreted as the property Count of a property WorkflowAssociation of the current object ($_). Which, of course, doesn't exist.

Upvotes: 2

Related Questions