2010-05-26 106 views
5

對不起,作爲一個超級痛苦的人,所有的非常新:(LDAP查詢的OU的

已經有關於這個幫助了很多,但似乎並沒有能夠看到這個問題,我想填充組合框與所有當前OU的列表,以後每一臺機器發送OU中的關機命令。(獲取AD OU列表&的Active Directory目錄OU的)是我之前常見的。

 string defaultNamingContext; 
     //TODO 0 - Acquire and display the available OU's 
     DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); 
     defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString(); 
     DirectoryEntry entryToQuery = new DirectoryEntry ("LDAP://" + defaultNamingContext); 
     MessageBox.Show(entryToQuery.Path.ToString()); 

     DirectorySearcher ouSearch = new DirectorySearcher(entryToQuery.Path); 
     ouSearch.Filter = "(objectCatergory=organizationalUnit)"; 
     ouSearch.SearchScope = SearchScope.Subtree; 
     ouSearch.PropertiesToLoad.Add("name"); 

     SearchResultCollection allOUS = ouSearch.FindAll(); 

     foreach (SearchResult oneResult in allOUS) 
     { 
      //comboBox1.Items.Add(oneResult.ToString()); 
      comboBox1.Items.Add(oneResult.Properties["name"][0]); 
     } 

我有通過並調試了我所知道的所有信息,搜索器沒有收到任何結果,因此爲什麼組合框中沒有填充任何內容。

+0

我剛剛嘗試手動添加整個LDAP路徑 entryToQuery =「LDAP:// OU = GTP,DC = GTP,DC = LOCAL」我知道樹中有部分OU在這裏,我有將該屬性替換爲加載到[「distinguishedName」]以查看是否可能p回想起來,雖然考慮到這一點,但沒有任何區別。超級難倒在這一點上! – 2010-05-26 15:10:06

+1

+1與AD相關的問題有趣的問題。 – 2010-05-27 14:27:52

回答

3

我不得不使用非索引 objectClass的而非CATERGORY。

你只需要正確拼寫:objectCategory - 不objectCate [R血腥

(你有一個 「R」 中有太多..... :-)

+1

我知道我應該更經常去學校:P – 2010-05-27 14:48:07

2

Works :) :)

我不得不使用非索引objectClass而不是Catergory。

現在組合框已經填充完美。

編輯: { 「(objectClass的=組織單元)。」 }

+1

+1爲了自己找到你的問題的答案,並把它提供給其他人可能正在尋找這樣的。在使用DirectorySearcher類時,請始終在DirectorySearcher.Filter屬性成員中提供「objectClass」屬性。 – 2010-05-27 14:27:29

+0

Thanks Will 爲什麼objectCatergory不起作用,任何人都知道? – 2010-05-27 14:39:26