我期望能够从Active Directory中获取当前OU的列表我一直在线查看一些示例代码,但O似乎无法使其工作。获取AD OU列表
string defaultNamingContext;
DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE");
defaultNamingContext = rootDSE.Properties["defaultNamingContext"].Value.ToString();
DirectorySearcher ouSearch = new DirectorySearcher(rootDSE, "(objectClass=organizationalUnit)",
null, SearchScope.Subtree);
MessageBox.Show(rootDSE.ToString());
try
{
SearchResultCollection collectedResult = ouSearch.FindAll();
foreach (SearchResult temp in collectedResult)
{
comboBox1.Items.Add(temp.Properties["name"][0]);
DirectoryEntry ou = temp.GetDirectoryEntry();
}
我得到的错误是提供程序不支持搜索并且无法搜索LDAP:// RootDSE Any Ideas? 对于每个返回的搜索结果,我想将它们添加到组合框中。 (不应该太难)
我试图用上面的建议进行搜索,它似乎是一个非常好的主意,虽然它有一个noob尝试实现它。我改变默认为'域',我看不出有问题在做,我的问题是该域= System.DirectoryServices.DirectoryEntry,而不是LDAP:// ...虽然这是在其路径属性。 – 2010-05-25 10:56:26
只是想我会补充任何后来发现这一点的人。 Server 2003 R2和更早版本不*索引'objectClass',但是2008年和更晚版本。不是对答案的敲门声!只是新的信息。资料来源:http://msdn.microsoft.com/en-us/library/ms675095(v=vs.85).aspx – klyd 2014-08-29 14:58:20