Getting effective property patterns

The following code sample outputs names and descriptions of property patterns effective for a user.

PowerShell
[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
}
    
C#
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();
        }
    }
}

The following code sample outputs names and descriptions of property patterns effective for multiple users.

PowerShell
[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
}
C#
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