我試圖為我的公司制作一個 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; }
1 回答

慕沐林林
TA貢獻2016條經驗 獲得超9個贊
配置DirectorySearcher
使其專門在Users
OU 中搜索,然后將SearchScope
屬性指定為SearchScope.OneLevel
(默認為SubTree
)。
不幸的是,唯一允許您同時指定兩者的構造函數重載是廚房水槽構造函數。
- 1 回答
- 0 關注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消