我試圖為我的公司制作一個 Active-Directory 管理工具,我想從特定的 OU 中獲取所有用戶,而不是得到 under(?)-OU 的結(jié)果。結(jié)構(gòu)是這樣的:->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貢獻(xiàn)2016條經(jīng)驗 獲得超9個贊
配置DirectorySearcher
使其專門在Users
OU 中搜索,然后將SearchScope
屬性指定為SearchScope.OneLevel
(默認(rèn)為SubTree
)。
不幸的是,唯一允許您同時指定兩者的構(gòu)造函數(shù)重載是廚房水槽構(gòu)造函數(shù)。
- 1 回答
- 0 關(guān)注
- 131 瀏覽
添加回答
舉報
0/150
提交
取消