0

I have a function witch tries to remove a member from a group

The problem is if you try to remove a member, without knowing the existence in the group, you could cause an exception. So I try to enumerate its membership beforehand.

The problem now is that the member property stops after 3000 Entries, and I don't know a way to get more, or the next 3000 members of that group.

Here is my code

DirectoryEntry target_group = new DirectoryEntry(LDAP_group_DN);
if (target_group.Properties["member"].Contains(LDAP_member_to_remove_DN)) {
    target_group.Properties["member"].Remove(LDAP_member_to_remove_DN);
}
target_group.CommitChanges();

target_group.Properties["member"] contains exactly 3000 entries, but in reality it is around 7500.

As a shorthand fix I am using the remove statement in a try/catch block without the .Contains() check, but that doesn't seem correct/beautiful/right.

Can anyone lead me to the correct way?

PS: I can not change the structure of our Directory. This is a Group of RADIUS users, with should not be split up in more groups!

Daywalker
  • 212
  • 1
  • 3
  • 17

2 Answers2

1

Instead of getting all the group members to determine if the user is part of that list I would use the memberOf/isMemberOf attribute (assuming that your directory supports this feature). This attribute will tell you if a user belongs to a group without having to retrieve all group members.

This other answer might help.

Community
  • 1
  • 1
Guillermo R
  • 623
  • 4
  • 8
  • I will give that a try today and let ou know if our MS AD supports this. – Daywalker Apr 11 '16 at 04:49
  • I tried to do a target_group.Properties["memberOf"].Remove(memberOf_DN); But it was not working :( (Server is unwilling to perform...). I think i will stick to th try catch block for now. The MaxValRange statement Is something I dint not manage to get working properly yet. – Daywalker Apr 13 '16 at 10:30
0

You need to look at into MaxValRange and learn how to retrieve more values using C#.

We have a very simple sample, but, alas, it is in Java

jwilleke
  • 10,467
  • 1
  • 30
  • 51