Distribution List Dynamiques

import-module activedirectory

$Application= »
$sgroup= »

Import-Csv c:\temp\source.csv -Delimiter ‘;’ | where-object { $_.’Create DL’ -eq ‘X’ } | Sort-Object DL_,AD | select-object DL_,AD -unique | foreach {
if ($_.DL_ -eq $Application) {
$sgroup+= »(MemberOfGroup -eq ‘ »+(Get-ADGroup $_.AD | Select-Object -ExpandProperty DistinguishedName)+ »‘) -or  »
} else {
if ($Application -ne  » ) {
$sgroup=$sgroup.Substring(0,$sgroup.Length-4)
Remove-DynamicDistributionGroup « $Application » -Confirm:$false
$a= »New-DynamicDistributionGroup ‘$Application’ -Alias ‘$Application’ -OrganizationalUnit ‘OU=Distribution Lists,OU=Groups,OU=Users and groups,DC=MonDomaine,DC=local’ -RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and ( ($sgroup)) }  »
invoke-expression $a

}
$Application=$_.DL_
$sgroup= »(MemberOfGroup -eq ‘ »+(Get-ADGroup $_.AD | Select-Object -ExpandProperty DistinguishedName)+ »‘) -or  »
}
}

if ($_.DL_ -ne $Application) {
$sgroup=$sgroup.Substring(0,$sgroup.Length-4)
Remove-DynamicDistributionGroup « $Application » -Confirm:$false
$a= »New-DynamicDistributionGroup ‘$Application’ -Alias ‘$Application’ -OrganizationalUnit ‘OU=Distribution Lists,OU=Groups,OU=Users and groups,DC=MonDomaine,DC=local’ -RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and ( ($sgroup)) }  »
invoke-expression $a

}

#########################################################

$MyGroup = Get-DynamicDistributionGroup -id MA_DDL
Get-Recipient -RecipientPreviewFilter $MyGroup.RecipientFilter

Laisser un commentaire