PrincipalCollection.Add Method

Definition

Adds the specified principal to the end of the collection.

Overloads

Add(ComputerPrincipal)

Adds the specified ComputerPrincipal object to the end of the collection.

Add(GroupPrincipal)

Adds the specified GroupPrincipal object to the end of the collection.

Add(Principal)

Adds the specified Principal object to the end of the collection.

Add(UserPrincipal)

Adds the specified UserPrincipal object to the end of the collection.

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)

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

Adds the specified ComputerPrincipal object to the end of the collection.

C#
public void Add(System.DirectoryServices.AccountManagement.ComputerPrincipal computer);
C#
[System.Security.SecurityCritical]
public void Add(System.DirectoryServices.AccountManagement.ComputerPrincipal computer);

Parameters

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException computer already exists in the collection.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Add(GroupPrincipal)

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

Adds the specified GroupPrincipal object to the end of the collection.

C#
public void Add(System.DirectoryServices.AccountManagement.GroupPrincipal group);
C#
[System.Security.SecurityCritical]
public void Add(System.DirectoryServices.AccountManagement.GroupPrincipal group);

Parameters

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException group already exists in the collection.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Add(Principal)

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

Adds the specified Principal object to the end of the collection.

C#
public void Add(System.DirectoryServices.AccountManagement.Principal principal);
C#
[System.Security.SecurityCritical]
public void Add(System.DirectoryServices.AccountManagement.Principal principal);

Parameters

principal
Principal

A Principal object.

Implements

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException principal already exists in the collection.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Add(UserPrincipal)

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

Adds the specified UserPrincipal object to the end of the collection.

C#
public void Add(System.DirectoryServices.AccountManagement.UserPrincipal user);
C#
[System.Security.SecurityCritical]
public void Add(System.DirectoryServices.AccountManagement.UserPrincipal user);

Parameters

user
UserPrincipal

A UserPrincipal object.

Attributes

Remarks

This function can throw the following exceptions:

Exception Description
PrincipalExistsException user already exists in the collection.

Applies to

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Add(PrincipalContext, IdentityType, String)

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

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

C#
public void Add(System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);
C#
[System.Security.SecurityCritical]
public void Add(System.DirectoryServices.AccountManagement.PrincipalContext context, System.DirectoryServices.AccountManagement.IdentityType identityType, string identityValue);

Parameters

context
PrincipalContext

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

identityType
IdentityType

An IdentityType object that specifies the format of identityValue.

identityValue
String

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

Attributes

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

.NET 10 (package-provided) и друге верзије
Производ Верзије
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)