Modifying organizational units

The following code sample modifies the Managed By property of an organizational unit.

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

The following code sample modifies
$ns = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$service = $ns.GetServiceDirectly("localhost")

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

$managedByDN = "CN=My Group,CN=Groups,DC=domain,DC=com"

# Update the organizational unit
$ou.Put("managedBy", $managedByDN)
$ou.SetInfo()
PowerShell
Import-Module Adaxes

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

$identityManagedBy = "MyGroup" # sAMAccountName
# $identityGroup = "CN=My Group,CN=Groups,DC=domain,DC=com"  # DN
# $identityGroup = "{D4BD8631-FD29-4E34-A77B-3505B7D66BA5}" # GUID
# $identityGroup = "S-1-5-21-573937-2149998-410785" # SID


Set-AdmOrganizationalUnit -Identity $identityOU -ManagedBy $identityManagedBy `
    -Server "domain.com" -AdaxesService localhost

See also