我试图为我的公司制作一个 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;
}
慕沐林林
相关分类