Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AF SDK Reference

PIIdentityMappings.Add Method (String, String, String, PIIdentityMappingType)

PIIdentityMappings.Add Method (String, String, String, PIIdentityMappingType)

  • Last UpdatedNov 18, 2025
  • 3 minute read
PIIdentityMappings.Add Method (String, String, String, PIIdentityMappingType)
Creates a new PIIdentityMapping with the passed in name.

Namespace:  OSIsoft.AF.PI
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public PIIdentityMapping Add(
	string name,
	string principalName,
	string identity,
	PIIdentityMappingType mappingType
)
Public Function Add ( 
	name As String,
	principalName As String,
	identity As String,
	mappingType As PIIdentityMappingType
) As PIIdentityMapping

Dim instance As PIIdentityMappings
Dim name As String
Dim principalName As String
Dim identity As String
Dim mappingType As PIIdentityMappingType
Dim returnValue As PIIdentityMapping

returnValue = instance.Add(name, principalName, 
	identity, mappingType)
public:
PIIdentityMapping^ Add(
	String^ name, 
	String^ principalName, 
	String^ identity, 
	PIIdentityMappingType mappingType
)
member Add : 
        name : string * 
        principalName : string * 
        identity : string * 
        mappingType : PIIdentityMappingType -> PIIdentityMapping 

Parameters

name
Type: SystemString
Name of the new PIIdentityMapping
principalName
Type: SystemString
Account Name of the new PIIdentityMapping
identity
Type: SystemString
The existing identity name that the new PIIdentityMapping will be mapped to
mappingType
Type: OSIsoft.AF.PIPIIdentityMappingType
The type of mapping for the new IdentityMapping. PIIdentityMappingType

Return Value

Type: PIIdentityMapping
Reference to the new PIIdentityMapping.

Exceptions

ExceptionCondition
InvalidOperationExceptionIf a PIIdentityMapping with the same name already exists.

Remarks

The PIIdentityMapping is not committed to the PIServer until CheckIn is called.

Examples

// Get the PIIdentityMappings from the PIServer on the local computer
PISystems myPISystems = new PISystems();
PISystem myPISystem = myPISystems.DefaultPISystem;
PIServer myPIServer = PIServer.FindPIServer(myPISystem, piServerName);

// Add a mapping, if it does not yet exist.
string newMapName = @"Windows\S-1-5-32-544";
string mapAIMServerAdministrators = @"Windows\S-1-5-32-544";
string identity = "piadmins";

PIIdentityMappings mappings = myPIServer.IdentityMappings;
PIIdentityMapping newMap;
if (!mappings.Contains(newMapName))
{
    // Note that adding or editing a mapping requires 'CheckIn' in order to commit it to the PI Data Archive.
    newMap = mappings.Add(newMapName, mapAIMServerAdministrators, identity, PIIdentityMappingType.Role);
    newMap.CheckIn();
}
else
    newMap = mappings[newMapName];

Console.WriteLine(newMap.Name);
Console.WriteLine("  ID: {0}", newMap.ID);
Console.WriteLine("  Description: {0}", newMap.Description);
Console.WriteLine("  Principal: {0}", newMap.Principal);
Console.WriteLine("  PrincipalName: {0}", newMap.PrincipalName);
Console.WriteLine("  Identity: {0}", newMap.Identity);
Console.WriteLine("  IdentityMappingType: {0}", newMap.IdentityMappingType);
Console.WriteLine("  IsEnabled: {0}", newMap.IsEnabled);
Console.WriteLine();

myPIServer.Connect(TestAccountAccessToken);

// Create a ClientCredential Mapping
newMap = null;
if (!mappings.Contains(TestClientId))
{
    // Note that adding or editing a mapping requires 'CheckIn' in order to commit it to the PI Data Archive.
    newMap = mappings.Add(TestClientId, TestClientId, identity, PIIdentityMappingType.ClientCredential);
    newMap.CheckIn();
}
else
    newMap = mappings[TestClientId];

Version Information

AFSDK

Supported in: 3.1.1, 3.1.0, 3.0.2, 3.0.1, 3.0.0

See Also

In This Topic
Related Links
TitleResults for “How to create a CRG?”Also Available in