PrincipalCollection.Add PrincipalCollection.Add PrincipalCollection.Add PrincipalCollection.Add Method

Definition

Adds the specified principal to the end of the collection.

Overloads

Add(ComputerPrincipal) Add(ComputerPrincipal) Add(ComputerPrincipal) Add(ComputerPrincipal)

Adds the specified ComputerPrincipal object to the end of the collection

Add(GroupPrincipal) Add(GroupPrincipal) Add(GroupPrincipal) Add(GroupPrincipal)

Adds the specified GroupPrincipal object to the end of the collection

Add(Principal) Add(Principal) Add(Principal)

Adds the specified Principal object to the end of the collection

Add(UserPrincipal) Add(UserPrincipal) Add(UserPrincipal) Add(UserPrincipal)

Adds the specified UserPrincipal object to the end of the collection

Add(PrincipalContext, IdentityType, String) Add(PrincipalContext, IdentityType, String) Add(PrincipalContext, IdentityType, String)

Searches for a Principal object that matches the parameters, and adds it to the end of the collection.

Remarks

As with Remove 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.

Add(ComputerPrincipal) Add(ComputerPrincipal) Add(ComputerPrincipal) Add(ComputerPrincipal)

Adds the specified ComputerPrincipal object to the end of the collection

public:
 void Add(System::DirectoryServices::AccountManagement::ComputerPrincipal ^ computer);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
member this.Add : System.DirectoryServices.AccountManagement.ComputerPrincipal -> unit
Public Sub Add (computer As ComputerPrincipal)

Parameters

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException computer already exists in the collection.

Add(GroupPrincipal) Add(GroupPrincipal) Add(GroupPrincipal) Add(GroupPrincipal)

Adds the specified GroupPrincipal object to the end of the collection

public:
 void Add(System::DirectoryServices::AccountManagement::GroupPrincipal ^ group);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.GroupPrincipal group);
member this.Add : System.DirectoryServices.AccountManagement.GroupPrincipal -> unit
Public Sub Add (group As GroupPrincipal)

Parameters

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException group already exists in the collection.

Add(Principal) Add(Principal) Add(Principal)

Adds the specified Principal object to the end of the collection

public:
 virtual void Add(System::DirectoryServices::AccountManagement::Principal ^ principal);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.Principal principal);
abstract member Add : System.DirectoryServices.AccountManagement.Principal -> unit
override this.Add : System.DirectoryServices.AccountManagement.Principal -> unit

Parameters

Implements

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException principal already exists in the collection.

Add(UserPrincipal) Add(UserPrincipal) Add(UserPrincipal) Add(UserPrincipal)

Adds the specified UserPrincipal object to the end of the collection

public:
 void Add(System::DirectoryServices::AccountManagement::UserPrincipal ^ user);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.UserPrincipal user);
member this.Add : System.DirectoryServices.AccountManagement.UserPrincipal -> unit
Public Sub Add (user As UserPrincipal)

Parameters

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException user already exists in the collection.

Add(PrincipalContext, IdentityType, String) Add(PrincipalContext, IdentityType, String) Add(PrincipalContext, IdentityType, String)

Searches for a Principal object that matches the parameters, and adds it to the end of the collection.

public:
 void Add(System::DirectoryServices::AccountManagement::PrincipalContext ^ context, System::DirectoryServices::AccountManagement::IdentityType identityType, System::String ^ identityValue);
[System.Security.SecurityCritical]
public void Add (System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
member this.Add : System.DirectoryServices.AccountManagement.PrincipalContext * System.DirectoryServices.AccountManagement.IdentityType * string -> unit

Parameters

context
PrincipalContext PrincipalContext PrincipalContext PrincipalContext

The PrincipalContext object for the principal to be added to the collection.

identityType
IdentityType IdentityType IdentityType IdentityType

An IdentityType object that specifies the format of identityValue

identityValue
String String String String

A string that identifies the principal, in the format specified by identityType

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException The principal matching these parameters already exists in the collection.
NoMatchingPrincipalException No principal matching the specified parameters was found.
MultipleMatchesException More than one principal matches the specified parameters.
ArgumentException identityType is an empty string

Applies to