We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Move user to manager's Organizational Unit

June 08, 2016 Views: 1786

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
Leave a comment
Loading...

Got questions?

Support Questions & Answers