Script repository

Set owner of parent Organizational Unit as manager for user

Updated on: Jan 18, 2026, Views: 2924

Managers and subordinates

The script sets the owner of the Organizational Unit where a user account is located as the user manager. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

# Bind to the OU where the user is located
$parent = $Context.BindToObject($Context.TargetObject.Parent)

try
{
    # Get the owner's DN
    $managerDN = $parent.Get("managedBy")
}
catch
{
    $Context.LogMessage("Cannot update a manager for the user because the user's Organizational Unit is not managed by anyone", "Warning") # TODO: modify me
    return
}

# Set manager
$Context.TargetObject.Put("manager", $managerDN)
$Context.TargetObject.SetInfo()

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    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.