猿问

GetAllUsers 问题,忽略从属 OU

我试图为我的公司制作一个 Active-Directory 管理工具,我想从特定的 OU 中获取所有用户,而不是得到 under(?)-OU 的结果。


结构是这样的:


->XXXX.de


-->Germany


--->Users (Here are the Users i want to get)


(These are the unnecessary OUs / Results)


----> Administrative accounts


----> Other Accounts

我的 DirectorySearcher 的 LDAP 链接 (ldapPath) 是


"LDAP://OU=Users,OU=Germany,DC=XXXX,DC=de".

代码:


public SearchResultCollection getAllUsers(string location)

{

    string ldapPath;


    SearchResultCollection allResults;


    try {


        ldapPath = getLdapPathFromLocation(location);


        DirectoryEntry entry = createDirectoryEntry(AD_BWFE, ldapPath);


        DirectorySearcher searcher = new DirectorySearcher(entry);


        searcher.PropertiesToLoad.Add("cn");

        searcher.PropertiesToLoad.Add("sAmAccountName");


        allResults = searcher.FindAll();


        return allResults;

    }


临摹微笑
浏览 134回答 1
1回答

慕沐林林

配置DirectorySearcher使其专门在UsersOU 中搜索,然后将SearchScope属性指定为SearchScope.OneLevel(默认为SubTree)。不幸的是,唯一允许您同时指定两者的构造函数重载是厨房水槽构造函数。
随时随地看视频慕课网APP
我要回答