2013-03-07 80 views
3

當前我使用groupprincipal類(.NET 3.5)的GetMembers方法(使用true)枚舉組中的所有成員。嵌套組)。枚舉包含域用戶(主要組)的Active Directory組成員(嵌套)

如果在子域組中,主域組(Domain-Users)是成員,我無法正確枚舉所有成員。所提到的方法不枚舉Domain-Users組。

任何想法,以避免這個問題?我需要一個快速算法。所以列舉每個組/分組不是一個好的解決方案。

+0

你試過.GetGroups()從GroupPrincipal對象嗎? – 2013-03-07 13:18:14

+0

GetGroups() - 相關GroupPrincipal的方法返回它是直接成員的組。不是相關GroupPrincipal本身的成員。 – ThiloL 2013-03-07 14:56:59

+0

您是否找到了解決此問題的解決方案?我自己正在努力。 – 2017-10-20 09:43:40

回答

0

我正在使用System.DirectoryServices發送LDAP查詢。

速度快;我用它來查詢〜100k用戶,大概需要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(); 
     } 
     //... 
    } 
} 

我希望它幫助。

+0

我想枚舉組的成員。 – ThiloL 2013-11-18 14:24:37

相關問題