The following script can be used in business rules, scheduled tasks and custom commands to remove all Direct Reports from the user on which the script is executed.
To run the script as a part of a rule, command or task, use the Run a program or PowerShell script action.
PowerShell
try
{
$subordinateDNs = $Context.TargetObject.GetEx("directReports")
}
catch
{
return # The user has no direct reports
}
foreach($subordinateDN in $subordinateDNs)
{
# Clear 'Manager' property of the direct report
$subordinate = $Context.BindToObjectByDN($subordinateDN)
$subordinate.Put("manager", $NULL)
$subordinate.SetInfo()
}
There is no need to enter the username anywhere. As it is mentioned in the script description, it should be executed in a custom command, business rule or scheduled task configured for the User object type. It will automatically work for the target user. The script is dedicated for Adaxes and will not work in Windows PowerShell.