Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 枚举Active Directory组成员(嵌套),包括域用户(主组)_C#_.net_Active Directory - Fatal编程技术网

C# 枚举Active Directory组成员(嵌套),包括域用户(主组)

C# 枚举Active Directory组成员(嵌套),包括域用户(主组),c#,.net,active-directory,C#,.net,Active Directory,目前,我使用groupprincipal类(.NET 3.5)(带true)的GetMembers方法枚举组的所有成员(包括嵌套组) 如果在子组中,主域组(域用户)是成员,则无法正确枚举所有成员。上述方法不枚举域用户组 有什么办法可以避免这个问题吗?我需要一个快速算法。因此,单独枚举每个组/子组不是一个好的解决方案。我使用System.DirectoryServices发送LDAP查询 它很快;我用它来查询约10万用户,需要20-30秒。 (但在外部域上,如果我在本地域上,速度会更快) 我是这样

目前,我使用groupprincipal类(.NET 3.5)(带true)的GetMembers方法枚举组的所有成员(包括嵌套组)

如果在子组中,主域组(域用户)是成员,则无法正确枚举所有成员。上述方法不枚举域用户组


有什么办法可以避免这个问题吗?我需要一个快速算法。因此,单独枚举每个组/子组不是一个好的解决方案。

我使用System.DirectoryServices发送LDAP查询

它很快;我用它来查询约10万用户,需要20-30秒。 (但在外部域上,如果我在本地域上,速度会更快)

我是这样做的:

DirectoryEntry DE = new DirectoryEntry("LDAP://OU=ou_to_search_recursively", user, password);
using (DirectorySearcher DSE = new DirectorySearcher(DE))
{
    DSE.PageSize = 1000;
    //get only users
    DSE.Filter = "(&(objectClass=user)(objectCategory=person))";
    //search recursively
    DSE.SearchScope = SearchScope.Subtree;
    //load the properties that you want
    DSE.PropertiesToLoad.Clear();
    DSE.PropertiesToLoad.Add("distinguishedName");
    DSE.PropertiesToLoad.Add("cn");
    DSE.PropertiesToLoad.Add("other_attribute_you_might_want");

    foreach (SearchResult u in DSE.FindAll())
    {
        //check if property exists
        if (u.Properties.Contains("distinguishedName")) {
            // access property: 
            string dn = u.Properties["distinguishedName"][0].ToString();
        }
        //...
    }
}

我希望这会有所帮助。

您是否尝试过GroupPrincipal对象中的.GetGroups()?相关GroupPrincipal的GetGroups()-方法返回其直接成员的组。不是相关的GroupPrincipal本身的成员。您找到解决此问题的方法了吗?我自己也在努力。我想列举一个小组的成员。