Skip to content

Moving Organizational Units

The following code sample moves an Organizational Unit to another location.

[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 target Organizational Unit
$targetOUDN = "OU=Target OU,DC=domain,DC=com"
$targetOU = $admService.OpenObject("Adaxes://$targetOUDN",
    $NULL, $NULL, 0)

# Move the Organizational Unit
$ouPath = "Adaxes://OU=Source OU,DC=domain,DC=com"
$targetOU.MoveHere($ouPath, $NULL)
Import-Module Adaxes

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

$targetOUDN = "OU=Target OU,DC=domain,DC=com"

Move-AdmObject -Identity $identityOU -TargetPath $targetOUDN `
    -Server "domain.com" -AdaxesService localhost

See also