Directory Services

Removing Users from a Group

The following code example shows how to remove users from a group. For this task, find the user to be removed, which in the example is User Name, then call the Remove method.

[C#]
DirectoryEntry dom = new DirectoryEntry();
DirectoryEntry ou = dom.Children.Find("OU=Consulting");
// Add a user to a group.
DirectoryEntry usr = ou.Children.Find("CN=User Name");String userDN = usr.Properties["distinguishedName"].Value.ToString();
group.Properties["member"].Remove(userDN);
group.CommitChanges();