Dynamic Distribution Group Based on Reporting Hierarchy

exchangemicrosoft-office-365

Is it possible to configure a dynamic distribution group to contain all direct reports of some person, plus all their direct reports recursively?

Verbose Info

To get the direct reports only I believe we'd just run:

Set-DynamicDistributionGroup -Identity 'SomeManagersDirectReports' `
    -RecipientFilter "((RecipientType -eq 'UserMailbox') -and (Manager -eq 'CN=SomeManager,OU=Users,DC=domain,DC=example,DC=com')" 

But to get a manager, their direct reports, and their reports recursively, the only way I can think of is to run something like the below to generate a list of members, then use that to update a (static) distribution group dynamically.

# very rough code to demo thinking... Haven't yet considered things like character escaping /
# circular loops / other fun things which may be found in the wild...

[string]$FirstPersonDn = 'CN=SomeManager,OU=Users,DC=domain,DC=example,DC=com'
[System.Collections.Generic.List[string]]$newMembers = [System.Collections.Generic.List[string]]::new()
[System.Collections.Generic.List[string]]$members = [System.Collections.Generic.List[string]]::new()
$newMembers.Add($FirstPersonDn)
while ($newMembers.Count) {
    $members.Add($newMembers)
    $newMembers = $newMembers | %{Get-AdUser $_ -properties DirectReports} | % DirectReports
}
Update-DistributionGroupMember -Identity 'SomeManagerAndTheirReportsRecusive' -Members $members

Best Answer

Based on my research, recursively delivering emails to the direct reports of the managers who are in the dynamic distribution group is not available, you may only add all reports to the group or create dynamic distribution group for each manager and add these DDLs to the parent distribution group.

Here is a similar thread for your reference, hope it helps: Create dynamic distribution group based on manager