Deleting organizational units

The following code sample deletes an organizational unit.

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

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

# Bind to the organizational unit
$ouDN = "OU=My OU,DC=domain,DC=com"
$ou = $service.OpenObject("Adaxes://$ouDN", $null, $null, 0)

# Delete the organizational unit
$ou.DeleteObject("ADM_DELETEOBJECTFLAGS_AUTO")
PowerShell
Import-Module Adaxes

$identity = "OU=My OU,DC=domain,DC=com"  # DN
# $identity = "{EB5FEB21-E648-42AD-B86C-89D3C6807953}" # GUID

Remove-AdmOrganizationalUnit -Identity $identity -Recursive -Server "domain.com" `
    -AdaxesService localhost -Confirm:$false

See also