GroupPrincipal.Members Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應