Muokkaa

Jaa


PrincipalCollection.Remove Method

Definition

Removes the specified principal from the collection, and returns true if the specified principal object was a member of the collection, and false otherwise (in which case no operation is performed).

Overloads

Remove(ComputerPrincipal)

Removes the specified ComputerPrincipal object from the collection, and returns true if the ComputerPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

Remove(GroupPrincipal)

Removes the specified GroupPrincipal object from the collection, and returns true if the GroupPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

Remove(Principal)

Removes the specified Principal object from the collection, and returns true if the Principal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

Remove(UserPrincipal)

Removes the specified UserPrincipal object from the collection, and returns true if the UserPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

Remove(PrincipalContext, IdentityType, String)

Finds the UserPrincipal object specified by the given PrincipalContext and identityType/identityValue pair from the collection, and returns true if the identified Principal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

Remarks

As with Add, and Contains there are four overloads to this function, but they all do the same thing. The extra overloads are only implemented to improve usability, so that developers using IntelliSense see overloads that take a UserPrincipal, GroupPrincipal, or ComputerPrincipal object. Calling any one of the User, Group, or Computer overloads is exactly equivalent to calling the Principal overload.

Remove(ComputerPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Removes the specified ComputerPrincipal object from the collection, and returns true if the ComputerPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

public:
 bool Remove(System::DirectoryServices::AccountManagement::ComputerPrincipal ^ computer);
public bool Remove (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
[System.Security.SecurityCritical]
public bool Remove (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
member this.Remove : System.DirectoryServices.AccountManagement.ComputerPrincipal -> bool
[<System.Security.SecurityCritical>]
member this.Remove : System.DirectoryServices.AccountManagement.ComputerPrincipal -> bool
Public Function Remove (computer As ComputerPrincipal) As Boolean

Parameters

Returns

true if the ComputerPrincipal was a member of this PrincipalCollection; otherwise, false.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
InvalidOperationException This method was called on the Members collection for a domain group, and the domain principal to be removed is a member of the group by virtue of its primaryGroupId attribute.

Applies to

Remove(GroupPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Removes the specified GroupPrincipal object from the collection, and returns true if the GroupPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

public:
 bool Remove(System::DirectoryServices::AccountManagement::GroupPrincipal ^ group);
public bool Remove (System.DirectoryServices.AccountManagement.GroupPrincipal group);
[System.Security.SecurityCritical]
public bool Remove (System.DirectoryServices.AccountManagement.GroupPrincipal group);
member this.Remove : System.DirectoryServices.AccountManagement.GroupPrincipal -> bool
[<System.Security.SecurityCritical>]
member this.Remove : System.DirectoryServices.AccountManagement.GroupPrincipal -> bool
Public Function Remove (group As GroupPrincipal) As Boolean

Parameters

group
GroupPrincipal

A GroupPrincipal object.

Returns

true if the GroupPrincipal was a member of this PrincipalCollection; otherwise, false.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
InvalidOperationException This method was called on the Members collection for a domain group, and the domain principal to be removed is a member of the group by virtue of its primaryGroupId attribute.

Applies to

Remove(Principal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Removes the specified Principal object from the collection, and returns true if the Principal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

public:
 virtual bool Remove(System::DirectoryServices::AccountManagement::Principal ^ principal);
public bool Remove (System.DirectoryServices.AccountManagement.Principal principal);
[System.Security.SecurityCritical]
public bool Remove (System.DirectoryServices.AccountManagement.Principal principal);
abstract member Remove : System.DirectoryServices.AccountManagement.Principal -> bool
override this.Remove : System.DirectoryServices.AccountManagement.Principal -> bool
[<System.Security.SecurityCritical>]
abstract member Remove : System.DirectoryServices.AccountManagement.Principal -> bool
override this.Remove : System.DirectoryServices.AccountManagement.Principal -> bool
Public Function Remove (principal As Principal) As Boolean

Parameters

principal
Principal

A Principal object.

Returns

true if the Principal was a member of this PrincipalCollection; otherwise, false.

Implements

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
InvalidOperationException This method was called on the Members collection for a domain group, and the domain principal to be removed is a member of the group by virtue of its primaryGroupId attribute.

Applies to

Remove(UserPrincipal)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Removes the specified UserPrincipal object from the collection, and returns true if the UserPrincipal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

public:
 bool Remove(System::DirectoryServices::AccountManagement::UserPrincipal ^ user);
public bool Remove (System.DirectoryServices.AccountManagement.UserPrincipal user);
[System.Security.SecurityCritical]
public bool Remove (System.DirectoryServices.AccountManagement.UserPrincipal user);
member this.Remove : System.DirectoryServices.AccountManagement.UserPrincipal -> bool
[<System.Security.SecurityCritical>]
member this.Remove : System.DirectoryServices.AccountManagement.UserPrincipal -> bool
Public Function Remove (user As UserPrincipal) As Boolean

Parameters

user
UserPrincipal

A UserPrincipal object.

Returns

true if the UserPrincipal was a member of this PrincipalCollection; otherwise, false.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
InvalidOperationException This method was called on the Members collection for a domain group, and the domain principal to be removed is a member of the group by virtue of its primaryGroupId attribute.

Applies to

Remove(PrincipalContext, IdentityType, String)

Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs
Source:
PrincipalCollection.cs

Finds the UserPrincipal object specified by the given PrincipalContext and identityType/identityValue pair from the collection, and returns true if the identified Principal was a member of this PrincipalCollection, and false otherwise (in which case the method performs no operation).

public:
 bool Remove(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::DirectoryServices::AccountManagement::IdentityType identityType, System::String ^ identityValue);
public bool Remove (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
[System.Security.SecurityCritical]
public bool Remove (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
member this.Remove : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> bool
[<System.Security.SecurityCritical>]
member this.Remove : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> bool
Public Function Remove (context As PrincipalContext, identityType As IdentityType, identityValue As String) As Boolean

Parameters

identityType
IdentityType

An IdentityType that identifies the format of identityValue.

identityValue
String

A string.

Returns

true if the identified Principal was a member of this PrincipalCollection; otherwise, false.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
InvalidOperationException This method was called on the Members collection for a domain group, and the domain principal to be removed is a member of the group by virtue of its primaryGroupId attribute.
NoMatchingPrincipalException No principal matching the specified parameters was found.
MultipleMatchesException More than one principal matches the specified parameters. In theory, this should never happen, because Add throws an exception when there is an attempt to add duplicate principals to the collection. However, it is possible that another API created the duplicate.
ArgumentException identityType is an empty string.

Applies to