简体   繁体   中英

C# Directory Service: How to get sub groups of groups in AD

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
}

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 (eg a recursive method).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM