Hello Gareth,
Thank you for the confirmation. There is no need to use any additional attributes. Also, for your information, Adaxes custom attributes cannot be used in search criteria. To achieve the desired, use the below script in a scheduled task configured for the User object type. The Activity Scope of the task should only include the CEO user. In the script, the $groupDN variable specifies the distinguished name (DN) of the group. For information on how to get an object DN, see https://adaxes.com/sdk/HowDoI.GetDnOfObject.
$groupDN = "CN=My group,OU=Groups,DC=domain,DC=com" # TODO: modify me
# Bind to the group
$group = $Context.BindToObjectByDN($groupDN)
# Get direct reports of target user
try
{
$directReportDNs = $Context.TargetObject.GetEx("directReports")
}
catch
{
# Remove all group members
$group.Put("member", $NULL)
$group.SetInfo()
return
}
$newMembers = New-Object System.Collections.ArrayList
foreach ($directReportDN in $directReportDNs)
{
# Get second level direct reports
$directReport = $Context.BindToObjectByDN($directReportDN)
try
{
$secondLevelReportDNs = $directReport.GetEx("directReports")
}
catch
{
continue
}
# Add second level direct reports to group
$newMembers.AddRange($secondLevelReportDNs)
}
# Update group members
if ($newMembers.Count -eq 0)
{
$group.Put("member", $NULL)
}
else
{
$group.Put("member", $newMembers.ToArray())
}
# Save the changes
$group.SetInfo()