Skip to content

Managing Property Patterns

This article describes how to manage Property Patterns using PowerShell scripts and C# code. The code samples included in this article can be used in stand-alone scripts and applications as well as in PowerShell scripts executed by Business Rules, Custom Commands, and Scheduled Tasks.

Creating a Property Pattern

To create a Property Pattern, first you need to bind to the container where you want to create it. All container objects support the IADsContainer interface, which provides methods and properties that manage the creation, deletion, and enumeration of child objects. To create a new Property Pattern, you need to call the Create method of the interface and pass “adm-PropertyPattern” as the first parameter of the method and the relative distinguished name (RDN) of the pattern as the second parameter. The object returned by the IADsContainer::Create method will support the IAdmPropertyPattern interface, using which you can specify the parameters of the new Property Pattern.

Use the IAdmPropertyPattern::ObjectType property to specify the type of directory objects the Property Pattern will apply to. The property must be set to a string that contains the name of an object class as defined in the Active Directory schema (e.g. “user”, “group”, “computer”, “organizationalUnit”). Using the IAdmPropertyPattern2::AdditionalObjectType property, you can specify an additional type of objects to which the Property Pattern will be applied.

The following code sample creates a Property Pattern to be applied to user objects.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the Property Patterns container
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath(
    "PropertyPatterns")
$propertyPatternsContainer = $admService.OpenObject($propertyPatternsPath,
    $NULL, $NULL, 0)

# Create a new Property Pattern
$pattern = $propertyPatternsContainer.Create("adm-PropertyPattern",
    "CN=My Pattern")

$pattern.ObjectType = "user"
$pattern.Description = "My description"
$pattern.Disabled = $False

# Save the Property Pattern
$pattern.SetInfo()
using System;
using Interop.Adsi;
using Interop.Adsi.PropertyPatterns;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        // Connect to the Adaxes service
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to the 'Property Patterns' container
        String propertyPatternsPath = admService.Backend.GetConfigurationContainerPath(
            "PropertyPatterns");
        IADsContainer propertyPatternsContainer = (IADsContainer)admService.OpenObject(
            propertyPatternsPath, null, null, 0);

        // Create a new Property Pattern
        IAdmPropertyPattern pattern = (IAdmPropertyPattern)propertyPatternsContainer.Create(
            "adm-PropertyPattern", "CN=My Pattern");

        pattern.ObjectType = "user";
        pattern.Description = "My description";
        pattern.Disabled = false;

        // Save the Property Pattern
        pattern.SetInfo();
    }
}

If your script is executed by a Business Rule, Custom Command or Scheduled Task, you can use a predefined PowerShell variable $Context to get the ADS path of the Property Patterns container and bind to the container. The type of the $Context variable is ExecuteScriptContextClass.

# Bind to the Property Patterns container
$propertyPatternsPath = $Context.GetWellKnownContainerPath("PropertyPatterns")
$propertyPatternsContainer = $Context.BindToObject($propertyPatternsPath)

# Create a new Property Pattern
$pattern = $propertyPatternsContainer.Create("adm-PropertyPattern", "CN=My Pattern")

$pattern.ObjectType = "user"
$pattern.Description = "My description"
$pattern.Disabled = $False

# Save the Property Pattern
$pattern.SetInfo()
How to create a Property Pattern in a specific container

The following code sample creates a Property Pattern in the container called My Container. The Property Pattern will apply to Group objects.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the Property Patterns container
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath(
    "PropertyPatterns")
# Build the ADS path of the child container 'My Container'
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath"`
    $propertyPatternsPath
$myContainerAdsPath = $propertyPatternsPathObj.CreateChildPath("CN=My Container")

$myContainer = $admService.OpenObject($myContainerAdsPath, $NULL, $NULL, 0)

# Create a new Property Pattern
$pattern = $myContainer.Create("adm-PropertyPattern", "CN=My Pattern")

$pattern.ObjectType = "group"
$pattern.Description = "My description"
$pattern.Disabled = $False

# Save the Property Pattern
$pattern.SetInfo()
using System;
using Interop.Adsi;
using Interop.Adsi.PropertyPatterns;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        // Connect to the Adaxes service
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to the Property Patterns container
        String propertyPatternsPath = admService.Backend.GetConfigurationContainerPath(
            "PropertyPatterns");
        // Build the ADS path of the child container 'My Container'
        AdsPath propertyPatternsPathObj = new AdsPath(propertyPatternsPath);
        AdsPath myContainerAdsPath = propertyPatternsPathObj.CreateChildPath(
            "CN=My Container");

        IADsContainer myContainer = (IADsContainer)admService.OpenObject(
            myContainerAdsPath.ToString(), null, null, 0);

        // Create a new Property Pattern
        IAdmPropertyPattern pattern = (IAdmPropertyPattern)myContainer.Create(
            "adm-PropertyPattern", "CN=My Pattern");

        pattern.ObjectType = "group";
        pattern.Description = "My description";
        pattern.Disabled = false;

        // Save the Property Pattern
        pattern.SetInfo();
    }
}

Note

For information on how to create containers for Property Patterns, see Creating Property Pattern containers.

Modifying a Property Pattern

To modify an existing Property Pattern, first you need to bind to the directory object representing the Property Pattern. For more information on how to bind to Adaxes-specific objects, see Binding to Adaxes-specific objects.

After you’ve bound to a Property Pattern object, you can use ADSI interfaces like IAdmPropertyPattern and IADs to modify the Property Pattern.

The following code sample binds to the built-in Property Pattern named User Pattern and deletes the Property Pattern item for the Description property.

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Build the ADS path of the built-in Property Pattern called 'User Pattern'
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath(
    "PropertyPatterns")
$propertyPatternsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" `
    $propertyPatternsPath
$builtinPathObj = $propertyPatternsPathObj.CreateChildPath("CN=Builtin")
$userPatternPath = $builtinPathObj.CreateChildPath("CN=User Pattern")

$pattern = $admService.OpenObject($userPatternPath.ToString(),
    $NULL, $NULL, 0)

# Delete the item for the 'Description' property
foreach ($item in $pattern.Items)
{
    if ($item.PropertyName -ieq "description")
    {
        $pattern.Items.Remove($item)
        break
    }
}
using System;
using Interop.Adsi.PropertyPatterns;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
class Program
{
    static void Main(string[] args)
    {
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Build the ADS path of the built-in Property Pattern called 'User Pattern'
        String propertyPatternsPath = admService.Backend.GetConfigurationContainerPath(
            "PropertyPatterns");
        AdsPath propertyPatternsPathObj = new AdsPath(propertyPatternsPath);
        AdsPath builtinPathObj = propertyPatternsPathObj.CreateChildPath(
            "CN=Builtin");
        AdsPath userPatternPath = builtinPathObj.CreateChildPath("CN=User Pattern");

        IAdmPropertyPattern pattern =
            (IAdmPropertyPattern)admService.OpenObject(
                userPatternPath.ToString(), null, null, 0);

        // Delete the item for the Description property
        foreach (IAdmPropertyPatternItem item in pattern.Items)
        {
            if (StringComparer.OrdinalIgnoreCase.Equals("description",
                item.PropertyName))
            {
                pattern.Items.Remove(item);
                break;
            }
        }
    }
}

Adding a Property Pattern item

To apply a Property Pattern to a specific property of AD objects, you need to add a Property Pattern item for the property. To access the collection of Property Pattern items, use the Items property of the IAdmPropertyPattern interface. The Items property supports the IAdmCollection interface, using which you can create, delete, and enumerate Property Pattern items.

To create a new Property Pattern item, call the Create method of the IAdmPropertyPattern::Items property. The object returned by the method will support the IAdmPropertyPatternItem interface, using which you can specify parameters of the new Property Pattern item.

  1. Specify the name of the property, to which the Property Pattern item will apply in the PropertyName field of the IAdmPropertyPatternItem interface. The value must be a string that contains the name of a directory object property as defined in the Active Directory schema (e.g. “department”, “cn”, “displayName”, “manager”).

  2. Set IAdmPropertyPatternItem::IsPropertyRequired to TRUE to mark the property as required.

  3. To set the default value for a property, use the DefaultValue field of the IAdmPropertyPatternItem interface.

    If you want the property value to be automatically generated based on values of other properties, use value references in the default property value. (e.g. %title% of the %department% department).

    If you want the property value to be generated during object creation, set IAdmPropertyPatternItem2::GenerateDefaultValueDuringCreating to TRUE.

    To enable automatic generation of the property value when an object is edited, set IAdmPropertyPatternItem::GenerateDefaultValueDuringEditing to TRUE.

  4. To define constraints for a directory object property, use GetConstraints and SetConstraints methods of the IAdmPropertyPatternItem interface. Using constraints, you can set the minimum and maximum length of values, enforce a regular expression pattern, provide a list of possible values, etc.

    The GetConstraints method returns a collection of constraints represented by the IAdmPropertyPatternConstraints interface. To create a new constraint, call the Create method of the interface and pass the constraint type as the parameter of the method. For a list of possible constraint types, see the ADM_PROPERTYCONSTRAINTTYPE_ENUM enumeration.

    The table below shows which interfaces are supported by different constraint types.

    Description
    Type
    Interface
    Text constraints (e.g. ‘must start with’, ‘must not contain’) ADM_PROPERTYCONSTRAINTTYPE_STRINGVALUE IAdmStringValueConstraint
    ‘Must match regexp’ ADM_PROPERTYCONSTRAINTTYPE_REGEXP IAdmRegexpConstraint
    Value range constraints (e.g. ‘Must be one of the following values’) ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE IAdmValueRangeConstraint
    Value length constraints ADM_PROPERTYCONSTRAINTTYPE_VALUELENGTH IAdmValueLengthConstraint

    To add a constraint to the list of constraints, call the Add method of the IAdmPropertyPatternConstraints interface.

    To apply constraints to a Property Pattern item, call the SetConstraints method of the item object.

  5. To set hint text for a property, use the Hint field of the IAdmPropertyPatternItem3 interface. The hint text is displayed in a tooltip when moving the mouse over the property input field. When possible, the hint text is also displayed inside the input field (as long as the field is empty).

  6. To provide custom help for a property:

    • Set IAdmPropertyPatternItem3::PropertyInfoMode to ADM_PROPERTYPATTERNINFOMODE_HELP.
    • Provide the help text via the IAdmPropertyPatternItem3::CustomHelpText property. You can use HTML tags in the help text.

In order to add a Property Pattern item to a Property Pattern, call the Add method of the IAdmPropertyPattern::Items property.

Example 1: Mark the Department property as required and provide a list of possible values for the property

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "department"
$item.IsPropertyRequired = $True

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE")
$constraint.AreValuesDenied = $False
$constraint.Values = @("IT", "HR", "Sales")
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)   
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
    (IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "department";
item.IsPropertyRequired = true;

IAdmPropertyPatternConstraints constraints =
    item.GetConstraints();
IAdmValueRangeConstraint constraint =
    (IAdmValueRangeConstraint)constraints.Create(
        ADM_PROPERTYCONSTRAINTTYPE_ENUM.ADM_PROPERTYCONSTRAINTTYPE_VALUERANGE);
constraint.AreValuesDenied = false;
constraint.Values = new Object[] { "IT", "HR", "Sales" };
constraints.Add(constraint);
item.SetConstraints(constraints);

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Example 2: Specify a template for generation of the Web Page property during user creation

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "wWWHomePage"
$item.DefaultValue = "http://www.example.com/Users/%username%/"
$item.GenerateDefaultValueDuringCreating = $True

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
    (IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "wWWHomePage";
item.DefaultValue = "http://www.example.com/Users/%username%/";
IAdmPropertyPatternItem2 item2 = (IAdmPropertyPatternItem2)item;
item2.GenerateDefaultValueDuringCreating = true;

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Example 3: Apply a regular expression constraint to the Telephone Number property

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "telephoneNumber"

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_REGEXP")
$constraint.RegularExpression = "^([0-9\(\)\/\+ \-]*)$"
$constraint.CustomErrorMessage = "Invalid phone number format!"
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
(IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "telephoneNumber";

IAdmPropertyPatternConstraints constraints =
item.GetConstraints();
IAdmRegexpConstraint constraint =
(IAdmRegexpConstraint)constraints.Create(
ADM_PROPERTYCONSTRAINTTYPE_ENUM.ADM_PROPERTYCONSTRAINTTYPE_REGEXP);
constraint.RegularExpression = "^([0-9\\(\\)\\/\\+ \\-]*)$";
constraint.CustomErrorMessage = "Invalid phone number format!";
constraints.Add(constraint);
item.SetConstraints(constraints);

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Example 4: Add a constraint for the Employee ID property saying that values of the property must not start from zero and must contain a dash

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "employeeID"

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_STRINGVALUE")
$constraint.NotStartWith = "0"
$constraint.Contain = "-"
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
    (IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "employeeID";

IAdmPropertyPatternConstraints constraints =
    item.GetConstraints();
IAdmStringValueConstraint constraint =
    (IAdmStringValueConstraint)constraints.Create(
        ADM_PROPERTYCONSTRAINTTYPE_ENUM.ADM_PROPERTYCONSTRAINTTYPE_STRINGVALUE);
constraint.NotStartWith = "0";
constraint.Contain = "-";
constraints.Add(constraint);
item.SetConstraints(constraints);

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Example 5: Set the minimum and maximum length of the Description property

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "description"

$constraints = $item.GetConstraints()
$constraint = $constraints.Create(
    "ADM_PROPERTYCONSTRAINTTYPE_VALUELENGTH")
$constraint.MinLength = 10
$constraint.MaxLength = 50
$constraints.Add($constraint)
$item.SetConstraints($constraints)

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
    (IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "description";

IAdmPropertyPatternConstraints constraints =
    item.GetConstraints();
IAdmValueLengthConstraint constraint =
    (IAdmValueLengthConstraint)constraints.Create(
        ADM_PROPERTYCONSTRAINTTYPE_ENUM.ADM_PROPERTYCONSTRAINTTYPE_VALUELENGTH);
constraint.MinLength = 10;
constraint.MaxLength = 50;
constraints.Add(constraint);
item.SetConstraints(constraints);

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Example 6: Provide custom hint and help for the Manager property

# The $pattern variable refers to a Property Pattern

$item = $pattern.Items.Create()
$item.PropertyName = "manager"

$item.Hint = "My hint"
$item.PropertyInfoMode ="ADM_PROPERTYPATTERNINFOMODE_HELP"
$item.CustomHelpText = "<h1>My Help</h1>My Text"

# Save the changes
$item.SetInfo()
$pattern.Items.Add($item)
// The pattern variable refers to a Property Pattern

IAdmPropertyPatternItem item =
(IAdmPropertyPatternItem)pattern.Items.Create();
item.PropertyName = "manager";

IAdmPropertyPatternItem3 item3 = (IAdmPropertyPatternItem3)item;
item3.Hint = "My hint";
item3.PropertyInfoMode =
ADM_PROPERTYPATTERNINFOMODE_ENUM.ADM_PROPERTYPATTERNINFOMODE_HELP;
item3.CustomHelpText = "<h1>My Help</h1>My Text";

// Save the changes
item.SetInfo();
pattern.Items.Add(item);

Defining the scope of activity

The activity scope of a Property Pattern determines the objects affected by the pattern. Activity scope can include whole domains, members of groups and Business Units, objects located in specific Organizational Units, etc.

To define the scope of activity of a Property Pattern, you need to use the ActivityScopeItems property of the IAdmPropertyPattern interface.

For information on how to define the activity scope of a Property Pattern, see Defining the scope of activity.

Getting effective Property Patterns

To get Property Patterns effective for Active Directory objects, first, you need to bind to the container where all Property Patterns are stored. For information on how to bind to the container, see Binding to ADSI objects.

The container for Property Patterns supports the IAdmPropertyPatternContainer interface, methods of which can be used to retrieve Property Patterns effective for AD objects.

Example 1: Output Property Patterns effective for a user

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the 'Property Patterns' container
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath("PropertyPatterns")
$propertyPatternsContainer = $admService.OpenObject($propertyPatternsPath, $NULL, $NULL, 0)

# Bind to the user
$userDN = "CN=John Smith,CN=Users,DC=domain,DC=com"
$user = $admService.OpenObject("Adaxes://$userDN", $NULL, $NULL, 0)

# Get effective Property Patterns
$propertyPatternsGuidsBytes = $propertyPatternsContainer.GetEffectivePropertyPatterns($user)

Write-Host "Property Patterns effective for the user:"
foreach ($guidBytes in $propertyPatternsGuidsBytes)
{
    # Bind to the Property Pattern
    $guid = [Guid]$guidBytes
    $patternPath = "Adaxes://<GUID=$guid>"
    $pattern = $admService.OpenObject($patternPath, $NULL, $NULL, 0)

    # Output information about the Property Pattern
    Write-Host "`tName:" $pattern.PatternName
    Write-Host "`tDescription:" $pattern.Description
    Write-Host
}
using System;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
using Softerra.Adaxes.Interop.Adsi.PropertyPatterns;

class Program
{
    static void Main(string[] args)
    {
         // Connect to the Adaxes service
         AdmNamespace adsNS = new AdmNamespace();
         IAdmService2 admService = (IAdmService2)adsNS.GetServiceDirectly("localhost");

         // Bind to the 'Property Patterns' container
         String propertyPatternsPath = admService.Backend.GetConfigurationContainerPath("PropertyPatterns");
         IAdmPropertyPatternContainer propertyPatternsContainer =
             (IAdmPropertyPatternContainer)admService.OpenObject(propertyPatternsPath, null, null, 0);

         // Bind to the user
         const String userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com";
         IAdmTop user = (IAdmTop)admService.OpenObject(userPath, null, null, 0);

         // Get effective Property Patterns
         object[] propertyPatternsGuidsBytes =
             (object[])propertyPatternsContainer.GetEffectivePropertyPatterns(user);

         Console.WriteLine("Property Patterns effective for the user:");
         foreach (byte[] guidBytes in propertyPatternsGuidsBytes)
         {
             //Bind to the Property Pattern
             String guid = new Guid(guidBytes).ToString("B");
             String patternPath = String.Format("Adaxes://<GUID={0}>", guid);
             IAdmPropertyPattern pattern = (IAdmPropertyPattern)admService.OpenObject(
                 patternPath, null, null, 0);


             // Output information about the Property Pattern
             Console.WriteLine("\tName: " + pattern.PatternName);
             Console.WriteLine("\tDescription: " + pattern.Description);
             Console.WriteLine();
          }
    }
}

Example 2: Output Property Patterns effective for multiple users

[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")

# Connect to the Adaxes service
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the 'Property Patterns' container
$propertyPatternsPath = $admService.Backend.GetConfigurationContainerPath("PropertyPatterns")
$propertyPatternsContainer = $admService.OpenObject($propertyPatternsPath, $NULL, $NULL, 0)

# User paths
$user1 = "Adaxes://CN=John Smith,CN=Users,DC=company,DC=com"
$user2 = "Adaxes://CN=Bob Jones,CN=Users,DC=company,DC=com"
$userPaths = @($user1, $user2)

# Get effective Property Patterns
$propertyPatternsGuidsBytes = 
    $propertyPatternsContainer.GetEffectivePropertyPatternsEx($userPaths)

Write-Host "Property Patterns effective for the users:"
foreach ($guidBytes in $propertyPatternsGuidsBytes)
{
    # Bint to the Property Pattern
    $guid = [Guid]$guidBytes
    $patternPath = "Adaxes://<GUID=$guid>"
    $pattern = $admService.OpenObject($patternPath, $NULL, $NULL, 0)

    # Output information about the Property Pattern
    Write-Host "`tName:" $pattern.PatternName
    Write-Host "`tDescription:" $pattern.Description
    Write-Host
}
using System;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;
using Softerra.Adaxes.Interop.Adsi.PropertyPatterns;

class Program
{
    static void Main(string[] args)
    {
        // Connect to the Adaxes service
        AdmNamespace adsNS = new AdmNamespace();
        IAdmService2 admService = (IAdmService2)adsNS.GetServiceDirectly("localhost");

        // Bind to the 'Property Patterns' container
        String propertyPatternsPath = admService.Backend.GetConfigurationContainerPath(
            "PropertyPatterns");
        IAdmPropertyPatternContainer propertyPatternsContainer =
            (IAdmPropertyPatternContainer)admService.OpenObject(propertyPatternsPath, null, null, 0);

        // User paths
        const String user1 = "Adaxes://CN=John Smith,CN=Users,DC=company,DC=com";
        const String user2 = "Adaxes://CN=Bob Jones,CN=Users,DC=company,DC=com";
        String[] userPaths = { user1, user2 };

        // Get effective Property Patterns
        object[] propertyPatternsGuidsBytes =
            (object[])propertyPatternsContainer.GetEffectivePropertyPatternsEx(userPaths);

        Console.WriteLine("Property Patterns effective for the user:");
        foreach (byte[] guidBytes in propertyPatternsGuidsBytes)
        {
            // Bind to the Property Pattern
            String guid = new Guid(guidBytes).ToString("B");
            String patternPath = String.Format("Adaxes://<GUID={0}>", guid);
            IAdmPropertyPattern pattern = (IAdmPropertyPattern)admService.OpenObject(
                patternPath, null, null, 0);

            // Output information about the Property Pattern
            Console.WriteLine("\tName: " + pattern.PatternName);
            Console.WriteLine("\tDescription: " + pattern.Description);
            Console.WriteLine();
        }
    }
}

See also