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.
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)