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

Add multiple Direct Reports

February 18, 2021 Views: 6463

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
PowerShell
# 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%") 
    $user.SetInfo()
}

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

Comments 13
avatar
usman Sep 16, 2021
i want to set manager for multiple users through csv via shell, any script or command pls?
avatar
Support Sep 22, 2021
Hello Usman,

Have a look at Script 2: Only update existing users from the following article in our repository:https://www.adaxes.com/script-repository/import-new-and-updated-users-from-csv-file-s246.htm.
Leave a comment
Loading...

Got questions?

Support Questions & Answers