Redigeeri

Jagamisviis:


GroupPrincipal.Members Property

Definition

Gets a collection of principal objects that represent the members of the group.

public:
 property System::DirectoryServices::AccountManagement::PrincipalCollection ^ Members { System::DirectoryServices::AccountManagement::PrincipalCollection ^ get(); };
public System.DirectoryServices.AccountManagement.PrincipalCollection Members { get; }
member this.Members : System.DirectoryServices.AccountManagement.PrincipalCollection
Public ReadOnly Property Members As PrincipalCollection

Property Value

A PrincipalCollection object that contains the principal objects that represent the members of the group.

Examples

The following code connects to the LDAP domain "fabrikam.com" with the username set to "administrator" and the password set to "SecretPwd123" in the PrincipalContext constructor.

A search is performed to find the group that has name "Domain Admins" under the container specified in the PrincipalContext constructor, "DC=fabrikam,DC=com." If the group is found, the user who has name "John Smith" is removed from the group and the user who has name "Jim Daly" is added to the group

PrincipalContext ctx = new PrincipalContext(ContextType.Domain,                                                                       
                                            "fabrikam.com",                                                                               
                                            "DC=fabrikam,DC=com",                                                                 
                                            "administrator",   
                                            "SecretPwd123");  

GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx,   
                                                   IdentityType.Name,   
                                                   "Domain Admins");  

if (grp != null)  
{  
    grp.Members.Remove(ctx, IdentityType.Name, "John Smith");            
    grp.Members.Add(ctx, IdentityType.Name, "Jim Daly");  
    grp.Save();  
    grp.Dispose();  
}  
ctx.Dispose();  

Remarks

For AD DS groups, the Members property includes user principals that are members of the group because of their primaryId Attribute. When the group contains these types of members, the following restrictions apply:

  • The Remove method cannot be used to remove members that are part of the group because of their primaryId Attribute.

  • The Clear method cannot be used to clear members that are part of the group because of their primaryId Attribute.

Applies to