Hi,
I am trying to create a dynamic distribution group in office 365, where I can create membership based on manager “ms” his reportees aging his reportees have reportees till last level.
I am still getting error in the recipientfilterscript block, can you validate and help me to understand
Hi,
I am trying to create a dynamic distribution group in office 365, where I can create membership based on manager "ms" his reportees aging his reportees have reportees till last level.
I am still getting error in the recipientfilterscript block, can you validate and help me to understand
$ManagerSAM = “MS”
function Get-AllReportees {
param (
[Parameter(Mandatory = $true)]
[string] $ManagerSAM
)
$directReports = Get-ADUser -Filter { Manager -eq $ManagerSAM } -Properties Manager
$allReportees = @()
foreach ($reportee in $directReports) {
if ($reportee.Name -ne $ManagerSAM -and $reportee.Manager -and $reportee.Manager -is [Microsoft.ActiveDirectory.Management.ADUser]) {
$childReports = Get-AllReportees -ManagerSAM $reportee.Manager.SamAccountName
$allReportees += $childReports
}
}
return $allReportees
}
$allMembers = Get-AllReportees -ManagerSAM $ManagerSAM
try {
$recipientFilterScript = {
$args[0].SamAccountName -eq $ManagerSAM -or $allMembers.SamAccountName -contains $args[0].SamAccountName
}
New-DynamicDistributionGroup -Name "DDG-MGR-MS" -RecipientFilter $recipientFilterScript
Write-Host "Dynamic Distribution group: DDG-MGR-MS Successfully created"
} catch {
Write-Error $_.Exception.Message
}