Registering managed domains

The following code sample adds a managed domain to Adaxes.

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

$domainName = "example.com"
$username = "administrator@example.com"
$password = "secret"

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

# Bind to the 'Managed Domains' container
$managedDomainsPath = $service.Backend.GetConfigurationContainerPath("ManagedDomains")
$managedDomainsContainer = $service.OpenObject($managedDomainsPath, $null, $null, 0)

# Register a new domain
$managedDomain = $managedDomainsContainer.Create("adm-ManagedDomain", "DC=$domainName")
$managedDomain.SetInfo()

$managedDomain.Register($username, $password)
C#
using System;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
        const string domainName = "example.com";
        const string username = "administrator@example.com";
        const string passowrd = "secret";

        // Connect to the Adaxes service
        AdmNamespace ns = new AdmNamespace();
        IAdmService service = ns.GetServiceDirectly("localhost");

        // Bind to the 'Managed Domains' container
        string managedDomainsPath = service.Backend.GetConfigurationContainerPath("ManagedDomains");
        IADsContainer managedDomainsContainer = (IADsContainer)service.OpenObject(
            managedDomainsPath, null, null, 0);

        // Register a new domain
        IAdmManagedDomain managedDomain = (IAdmManagedDomain)managedDomainsContainer.Create(
            "adm-ManagedDomain", "DC=" + domainName);
        managedDomain.SetInfo();

        managedDomain.Register(username, passowrd);
    }
}

See also