我正在努力阅读有史以来AD集团的所有成员。我用以下代码获取组
PrincipalContext yourOU = new PrincipalContext(ContextType.Domain, "test.domain.CH", "OU=Verteiler,OU=Gruppen,OU=SGV,OU=Gruppe_04,OU=Kunden,DC=test,DC=domain,DC=CH");
GroupPrincipal findAllGroups = new GroupPrincipal(yourOU, "*");
PrincipalSearcher ps = new PrincipalSearcher(findAllGroups);
foreach (var group in ps.FindAll())
{
Console.WriteLine(group.DisplayName);
}
现在我试图向每个组显示每个用户。
我怎么处理这个?
我自己尝试过,请在您的foreach中调用以下代码并发送您的Groupname
static async void populateGroups(string ADGroupName)
{
// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
// find the group in question
GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, ADGroupName);
// if found....
if (group != null)
{
// iterate over members
foreach (Principal p in group.GetMembers())
{
// Console.WriteLine("{0}: {1}", p.StructuralObjectClass, p.DisplayName);
// do whatever you need to do to those members
UserPrincipal theUser = p as UserPrincipal;
if (theUser != null)
{
if (theUser.IsAccountLockedOut())
{
Console.WriteLine("The user: {0} is member of following Group {1}", theUser, ADGroupName);
}
else
{
Console.WriteLine("The user: {0} is member of following Group {1}", theUser, ADGroupName);
}
}
}
}
}