LDAP Query for OU's
- by Stephen Murby
Sorry for being an uber pain people, its all very new :(
Already had alot of help on this, but don't seem to be able to see the problem, I am trying to populate a combo box with a list of all the current OU's, later to send each machine within that OU a shutdown command. (Acquiring AD OU list & Active Directory list OU's) were my previous Q's.
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]);
}
I have been through and debugged everything i know, the searcher isn't picking up any results, hence why nothing is populated in the combo box.