Directory Services

Adding Users to a Group

When a group is created, you must add users to the group. This topic describes how to add a user to a group. For more information about how to move existing users from one group to another, see Moving Directory Objects.

The following code example shows how to add a user, New User, to the Consulting organizational unit.

[C#]
DirectoryEntry dom = new DirectoryEntry();
DirectoryEntry ou = dom.Children.Find("OU=Consulting");
// Add User to a group;
DirectoryEntry usr = ou.Children.Find("CN=New User");
// To add multiple users to a group use AddRange( new string[] {"...userDnHere","...userDnHere..."});
group.Properties["member"].Add(usr.Properties["distinguishedName"].Value);
group.CommitChanges();