Script Repository

Set owner of parent Organizational Unit as manager for user

February 22, 2021

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
# Bind to the OU where the user is located
$parent = $Context.BindToObject($Context.TargetObject.Parent)

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

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

Comments ( 0 )
No results found.
Leave a comment