Acquiring AD OU list.
Posted
by Stephen Murby
on Stack Overflow
See other posts from Stack Overflow
or by Stephen Murby
Published on 2010-05-25T09:45:57Z
Indexed on
2010/05/25
9:51 UTC
Read the original article
Hit count: 383
Hi, I am looking to be able to pull a list of current OU's from Active Directory I have been looking at some example code online for sometime, but O don't seem to be able to get this to work.
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();
}
The error I get is There provider does not support searching and cannot search LDAP://RootDSE Any Ideas? for each of those returned search results I want to add them to a combo box. (shouldn't be too hard)
© Stack Overflow or respective owner