How to get list of Organizational Unit in Active Directory

  • Thread starter Thread starter killbill
  • Start date Start date
K

killbill

Hi All,
I am facing a problem to get list of all Organizational Units within
specific node. I am trying different filters but could not get desired
result.

Any suggestion how to do that ???

Thanks

Bill
 
I am facing a problem to get list of all Organizational Units within
specific node. I am trying different filters but could not get desired
result.

1) Set the root entry from which to search

DirectoryEntry rootEntry = new
DirectoryEntry("LDAP://ou=MyOU,dc=mycompany,dc=com")

2) Set up the directory searcher

DirectorySearcher dsFindOUs = new DirectorySearcher(rootEntry);

dsFindOUs.Filter = "(objectClass=organizationalUnit)";

dsFindOUs.SearchScope = SearchScope.SubTree;

dsFindOUs.PropertiesToLoad.Add("displayName");

foreach(SearchResult result in dsFindOUs.FindAll() )
{
Console.WriteLine("Found: " +
result.Properties["displayName"].Value.ToString());
}

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top