Reputation: 4350
How do I get sub groups from the Groups using directory service.
Assuming I have the following groups in AD:
Master Group
Group 1
Group 2
I want to get all groups that belong to Master Group. So in my case I want to get a list that contains Group 1 and Group 2
Here is part of my code:
using (var ctx = new PrincipalContext(ContextType.Domain, "myDomain.COM"))
{
var group = GroupPrincipal.FindByIdentity(ctx, "Master Group");
var results = group.Group();// returns nothing
}
Upvotes: 0
Views: 837
Reputation: 1749
There is no Group(bool)
method in GroupPrincipal
.
I guess you mean the GetMembers(bool) method?
When true
is passed to GetMembers
all the child groups are skipped (it returns only leaf objects like the users or computers).
You may pass a false
instead and filter out all non-group members. But this means you only get the direct member groups and need to have some way to get all the nested member groups (e.g. a recursive method).
Upvotes: 2