GroupPrincipal.Members 属性
定义
获取主体对象的集合,这些对象表示组的成员。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
属性值
一个包含主体对象的 PrincipalCollection 对象,这些对象表示组的成员。A PrincipalCollection object that contains the principal objects that represent the members of the group.
示例
以下代码将连接到 LDAP 域 "fabrikam.com",并将用户名设置为 "管理员",并在构造函数中将密码设置为 "SecretPwd123" PrincipalContext 。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.
执行搜索以查找在 PrincipalContext 构造函数 "DC = fabrikam,DC = com" 中指定的容器下具有名称 "域管理员" 的组。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." 如果找到了组,则会从组中删除名为 "John Smith" 的用户,并将名为 "Jim Daly" 的用户添加到该组中。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();
注解
对于 AD DS 组, Members 属性包括作为组成员的用户主体,因为其 PrimaryId 属性。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:
Remove由于 PrimaryId 属性的原因,不能使用方法删除属于该组的成员。The Remove method cannot be used to remove members that are part of the group because of their primaryId Attribute.
Clear方法不能用于清除属于组的成员,因为其 PrimaryId 属性。The Clear method cannot be used to clear members that are part of the group because of their primaryId Attribute.