1

I have a PowerShell object and I want to filter the results.

public Collection<PSObject> Groups;

I have successfully achieved this using linq if I need to filter based on a direct member. But what if I want to filter based on an object 1 or 2 levels deep?

Here is the linq query to filter on a direct member:

var groupMembershipFilter = (dynamic)CsQ.Groups.Where(x => x.Members["AgentsByUri"].Value != null).ToList();

However I need to drill down another level. In PowerShell this would be easy:

$x.AgentsByUri.AbsoluteUri

I have tried all sorts but cant figure out how to make this work. So that you can better understand the object structure here are a couple of screen shots:

enter image description here

enter image description here

enter image description here

From the above screen shots you can see the "AgentsByUri" is a collection. Inside that collection I want to test if the property "AbsoluteUri" contains a certain string value.

The other thing I dont understand is why I have to use "Members" and cant just use "BaseObject" - this structure look far more similar to PowerShell and would be my preference if possible as it translates better to my PowerShell brain.

Excuse my terminology, I'm reasonably new to C#! Hopefully this makes sense :)

Any help or guidance would be much appreciated.

1 Answer 1

0

Try this:

var groupMembershipFilter = (dynamic)CsQ.Groups.Where(x => x.Members["AgentsByUri"].Any(x => x.AbsoluteUri == "url")).ToList();
Sign up to request clarification or add additional context in comments.

1 Comment

Cheers for this, didnt seem to like the Any bit. I have made a bit of progress and posted a new question here as I think this one may be overly confusing - stackoverflow.com/questions/32511346/…

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.