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:
- 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.
- 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:
- [Optionally] Change the name under which the Secretary property appears in Adaxes.
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()
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.