无法在群组中找到Windows用户?

时间:2011-12-12 14:52:32

标签: c# ldap windows-server-2008 windows-authentication

尝试获取组中的用户列表。我可以在一个OU和东西中获得用户。但该组织没有工作!我已经把这个小组从OU中取出来并把它放在根本中,希望这会有所帮助,但事实并非如此。

CN = thisisthegroup,DC = thisisthedomain,DC = COM

任何帮助将不胜感激,我是LDAP的新手。感谢。

1 个答案:

答案 0 :(得分:1)

你可以这样尝试

static void Main(string[] args)
{
    string groupName = "Domain Users";
    string domainName = "";

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domainName);
    GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName);

    if (grp != null)
    {
         foreach (Principal p in grp.GetMembers(false))
         {
                Console.WriteLine(p.SamAccountName + " - " + p.DisplayName);
         }

        grp.Dispose();
        ctx.Dispose();
        Console.ReadLine();
    }
    else
    {
        Console.WriteLine("\nWe did not find that group in that domain, perhaps the group resides in a different domain?");
        Console.ReadLine();
    }
}

或者您可以尝试How to get Users Belonging to Active Directory group

上此链接中指定的那个
相关问题