Script Repository


Add multiple Direct Reports

September 29, 2015
1601

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 ( 0 )
No results found.
Leave a comment