Skip to content

Moving user accounts

The following code sample moves a user account from one Organizational Unit to another.

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

# Move the user
$userPath = "Adaxes://CN=John Smith,CN=Users,DC=domain,DC=com"
$movedUser = $targetOU.MoveHere($userPath, $NULL)
Import-Module Adaxes

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

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

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

See also