Skip to content

Adding domains

The following code sample adds a managed domain to Adaxes.

[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)

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

# Provide logon information
$managedDomain.Register($username, $password)
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);

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

         // Provide logon information
         managedDomain.Register(username, passowrd);
    }
}

See also