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()
}