Skip to content

Creating Organizational Units

The following code sample creates an Organizational Unit in Active Directory.

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

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

# bind to the domain
$domainDN = "DC=domain,DC=com"
$domain = $admService.OpenObject("Adaxes://$domainDN", `
    $NULL, $NULL, 0)

# Create a new Organizational Unit
$ou = $domain.Create("organizationalUnit", "OU=New Organizational Unit")
$ou.SetInfo()
Import-Module Adaxes

$domainDN = "DC=domain,DC=com"

New-AdmOrganizationalUnit -Name "New Organizational Unit" -Path $domainDN `
    -Server "domain.com" -AdaxesService localhost

See also