GetAllUsers问题,忽略从属OU

时间:2018-12-12 11:20:11

标签: c# active-directory

我正在尝试为我的公司制作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-Link(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;
    }

1 个答案:

答案 0 :(得分:2)

配置DirectorySearcher,以便在Users OU中进行特定搜索,然后将SearchScope属性指定为SearchScope.OneLevel(默认为SubTree)。

不幸的是,唯一可以同时指定两者的构造函数重载是kitchen sink constructor