LDAP查询的OU的

问题描述:

对不起,作为一个超级痛苦的人,所有的非常新:(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

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

你只需要正确拼写:objectCategory - 不objectCate [R血腥

(你有一个 “R” 中有太多..... :-)

+1

我知道我应该更经常去学校:P – 2010-05-27 14:48:07

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