Skip to content

Removing domains

The following code sample removes a managed domain from Adaxes.

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

$domainName = "example.com"

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

# Build ADS path to the managed domain
$managedDomainsPath = $admService.Backend.GetConfigurationContainerPath("ManagedDomains")
$managedDomainsPathObj = New-Object "Softerra.Adaxes.Adsi.AdsPath" $managedDomainsPath
$managedDomainPath = $managedDomainsPathObj.CreateChildPath("DC=$domainName")

# Bind to the domain
$managedDomain = $admService.OpenObject($managedDomainPath, $NULL, $NULL, 0)

# Remove the domain
$managedDomain.Unregister()
using System;
using Softerra.Adaxes.Adsi;
using Softerra.Adaxes.Interop.Adsi.PersistentObjects;

class Program
{
    static void Main(string[] args)
    {
        const String domainName = "example.com";

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

        // Build ADS path to the managed domain
        string managedDomainsPath = admService.Backend.GetConfigurationContainerPath(
            "ManagedDomains");
        AdsPath managedDomainsPathObj = new AdsPath(managedDomainsPath);
        AdsPath managedDomainPath = managedDomainsPathObj.CreateChildPath("DC=" + domainName);

        // Bind to the domain
        IAdmManagedDomain managedDomain = (IAdmManagedDomain)admService.OpenObject(
            managedDomainPath.ToString(), null, null, 0);

        // Remove the domain
        managedDomain.Unregister();
    }
}

See also