How can I get a list of every user and/or Group that is located inside of an LDAP organization unit?
I am trying to query my LDAP
server using c#
. I want to get a list of all my distribution lists. All of my distribution lists are grouped under an organization-unit (OU) called "General Distributions." How can I get a list of all members under the "General Distributions" OU?
Below is the code I am using to query the LDAP
service which is returning no results.
try
{
DirectoryEntry objADAM = new DirectoryEntry("LDAP://my_domain.com", "user@my_domain.com", "password");
DirectorySearcher objSearchADAM = new DirectorySearcher(objADAM);
objSearchADAM.Filter = "(&(OU=General Distributions,DC=my_domain,DC=com)";
objSearchADAM.SearchScope = SearchScope.Subtree;
SearchResultCollection objSearchResults = objSearchADAM.FindAll();
// Binding path.
List<string> result = new List<string>();
if (objSearchResults.Count != 0)
{
foreach (SearchResult objResult in objSearchResults)
{
DirectoryEntry objGroupEntry = objResult.GetDirectoryEntry();
result.Add(objGroupEntry.Name);
}
return result;
}
throw new Exception("No result found");
}
catch (Exception e)
{
throw e;
}