Click to Rate and Give Feedback
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
 
Adding Members to a Group 

When a group is created, members must be added to the group. This topic describes how to add members to a group.

Members are added to a group by adding the distinguished name of the member to the member attribute of the group. (For more information about the member attribute in the Active Directory Schema, see the topic "Member Attribute" in the MSDN Library at http://msdn.microsoft.com/library.) This can be accomplished with either the Add or AddRange method.

To add a single member to a group, add the member's distinguished name to the member property on the group object using the Add method.

The following C# example demonstrates how to add a single member to a group.

C#
// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// Add the user to the group.
group.Properties["member"].Add(userDN);

// Commit the changes to the group.
group.CommitChanges();

The following Visual Basic .NET example demonstrates how to add a single member to a group.

Visual Basic
' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' Add the user to the group.
group.Properties("member").Add(userDN)

' Commit the changes to the group.
group.CommitChanges()

To add multiple members to a group in a single operation, add the members' distinguished names to the member property on the group object using the AddRange method.

The following C# example demonstrates how to add multiple members to a group.

C#
// Bind to the group.
DirectoryEntry group = dom.Children.Find(groupDN);

// To add multiple users to a group, use the AddRange method.
group.Properties["member"].AddRange(new string[] {userDN1, userDN2});

// Commit the changes to the group.
group.CommitChanges();

The following Visual Basic .NET example demonstrates how to add multiple members to a group.

Visual Basic
' Bind to the group.
Dim group As New DirectoryEntry(groupDN)

' To add multiple users to a group, use the AddRange method.
group.Properties("member").AddRange(New String() {userDN1, userDN2})

' Commit the changes to the group.
group.CommitChanges()
NoteNote

These examples require the .NET Framework version 1.0 Service Pack 3 and later or the .NET Framework version 1.1 Service Pack 1 and later.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker