I’m trying to get all groups and their related sub groups and members from LDAP.
I’m using this code :
public List<Group> GetGroups()
{
DirectoryEntry de = new DirectoryEntry("LDAP://someLdap.com");
DirectorySearcher searcher = new DirectorySearcher(de);
searcher.Filter = "(&(objectClass=group))";
searcher.PageSize = 500;
searcher.PropertiesToLoad.Add("sAMAccountName");
searcher.PropertiesToLoad.Add("description");
searcher.PropertiesToLoad.Add("memeber");
searcher.PropertiesToLoad.Add("memeberOf");
searcher.SearchScope = SearchScope.Subtree;
List<Group> groups;
using (SearchResultCollection results = searcher.FindAll())
{
int count = 1;
groups = new List<Group>();
foreach (SearchResult result in results)
{
Group group = new Group();
if (result == null) continue;
Console.WriteLine(count++); // just to print
group.Name = result.Properties["sAMAccountName"][0].ToString();
group.Description = result.Properties["description"][0].ToString();
ResultPropertyValueCollection valueCollection =
result.Properties["memeber"];
foreach (var user in valueCollection)
{
group.Users.Add(user.ToString());
}
groups.Add(group);
}
}
return groups;
}
The code only works with sAMAccountName and description
But I’m not able to get all member and memberOf values
Any ideas?
That’s because you have misspelt both attribute names throughout your code and your post.