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

Set owner of parent Organizational Unit as manager for user

February 22, 2021 Views: 2115

The script sets the owner of the Organizational Unit where a user account is located as the user's manager. To specify user managers using the script, you need to create business rule that run the script automatically once a user account is created in AD or moved to another Organizational Unit. For an example of a business rule that runs a script once a new user is created, see Run PowerShell Script after Creating a User.

Edit Remove
PowerShell
# 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
Leave a comment
Loading...

Got questions?

Support Questions & Answers