How to get a list of groups in an Active Directory group
Posted
by Douglas Anderson
on Stack Overflow
See other posts from Stack Overflow
or by Douglas Anderson
Published on 2010-06-03T00:19:54Z
Indexed on
2010/06/03
0:24 UTC
Read the original article
Hit count: 752
I'm trying to get a list of the groups that are in an AD group using .NET.
As an example, I have a group called TestGroup and inside that group I have the group DomainAdministrators.
Using the code below I can get all of the users including those from the DomainAdministrators group but not the group itself.
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "DomainName");
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, "TestGroup");
ArrayList members = new ArrayList();
if (grp != null)
{
foreach (Principal p in grp.GetMembers(true))
{
members.Add(p.Name)
}
}
grp.Dispose();
ctx.Dispose();
Instead of GetMembers I've tried GetGroups but that doesn't return anything. How can I return the groups in the group?
© Stack Overflow or respective owner