Script Repository


Move user to manager's Organizational Unit

June 08, 2016
1391

The script moves a user to the Organizational Unit where their manager is located.

Note: Employee-manager relationships are established in Active Directory via the Manager property of a user's account.
Edit Remove
PowerShell
# Get the manager
try
{
    $managerDN = [Softerra.Adaxes.Ldap.DN]$Context.TargetObject.Get("manager")
}
catch
{
    $Context.LogMessage("The user doesn't have a manager", "Warning") # TODO: modify me
    return
}

# Get the container where the manager is located
$managerParentDN = $managerDN.Parent

if ($managerParentDN -eq "%adm-ParentDN%")
{
    return
}

# Move the user
$targetContainer = $Context.BindToObjectByDN($managerParentDN)
$targetContainer.MoveHere($Context.TargetObject.AdsPath, $NULL)

Comments ( 0 )
No results found.
Leave a comment