Script Repository

Add multiple Direct Reports

February 18, 2021

If you need to add multiple direct reports to a manager, instead of specifying the user in the Manager property of each direct report one-by-one, you can do this in bulk with the help of the below script. It will add users specified in the Secretary property of a user as his/her direct reports.

Note: Relationships between direct reports and managers are established in Active Directory via the Manager property of a user's account.

To use the script with Adaxes, you need to:

  1. Add the Secretary property to the form for editing users, if it is not present there. For information on how to do this, see step 6 of the following tutorial: Customize Forms for User Creation and Editing.
  2. Configure a business rule that will run the script after updating the Secretary property of a user. To add the script to your business rule, use the Run a program or PowerShell script action. Sample business rule:

  3. [Optionally] Change the name under which the Secretary property appears in Adaxes.
Edit Remove
# Get subordinates
$subordinateDNs = $Context.TargetObject.GetEx("secretary")

# Set user as manager of each subordinate
foreach ($dn in $subordinateDNs)
    $user = $Context.BindToObjectByDN($dn)
    $user.Put("manager", "%distinguishedName%") 

# Clear the Secretary property
$Context.TargetObject.PutEx("ADS_PROPERTY_CLEAR", "secretary", $NULL)

Comments ( 2 )
Sep 16, 2021
i want to set manager for multiple users through csv via shell, any script or command pls?
Sep 22, 2021
Hello Usman,

Have a look at Script 2: Only update existing users from the following article in our repository:
Leave a comment