Skip to content

Getting effective Property Patterns

The following code sample outputs names and descriptions of 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();
         }
    }
}

The following code sample outputs names and descriptions of 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