Registering 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
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")

# Bind to the 'Managed Domains' container
$managedDomainsPath = $admService.Backend.GetConfigurationContainerPath("ManagedDomains")
$managedDomainsContainer = $admService.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 adsNS = new AdmNamespace();
        IAdmService admService = adsNS.GetServiceDirectly("localhost");

        // Bind to the 'Managed Domains' container
        string managedDomainsPath = admService.Backend.GetConfigurationContainerPath("ManagedDomains");
        IADsContainer managedDomainsContainer = (IADsContainer)admService.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