r/PowerShell • • Nov 17 '25

update dynamic distribution list

i am in an environment running exchange 2019 hybrid with a bunch of DDLs. Any tips on how i can add an extra CustomAttribute to this rule and perhaps include a security group? I know the command is Set-DynamicDistributionGroup but my head hurts just looking at this and trying to workout an easy way to read it and know where to make the addition. I suspect it was created many exchange versions ago

((((((((((((((((((((((((((Company -eq 'Contoso') -and (CustomAttribute4 -eq 'City'))) -and (((((CustomAttribute7 -eq 'Group') -or (CustomAttribute7 -eq 'Contractor'))) -or (CustomAttribute7 -eq 'Permanent'))))) -and (((RecipientType -eq 'UserMailbox') -or (((RecipientType -eq 'MailUser') -and (CustomAttribute12 -ne 'Excluded'))))))) -and (-not(Name -like 'SystemMailbox{*')))) -and (-not(Name -like 'CAS_{*')))) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')))) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')))) -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')))) -and (-not(Name -like 'SystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox')))

0 Upvotes

9 comments sorted by

View all comments

Show parent comment

1

u/alokin123 Nov 17 '25

well i tried and it gave me this. At least its given me a clue as to where to add the extra stuff i need. I havent tested it though...

Set-DynamicDistributionGroup -Identity "Your-DDG-Name" -RecipientFilter "(

(

(Company -eq 'Contoso') -and

(CustomAttribute4 -eq 'City') -and

(

(CustomAttribute7 -eq 'Group') -or

(CustomAttribute7 -eq 'Contractor') -or

(CustomAttribute7 -eq 'Permanent')

) -and

(

(RecipientType -eq 'UserMailbox') -or

((RecipientType -eq 'MailUser') -and (CustomAttribute12 -ne 'Excluded'))

) -and

(extensionAttribute3 -eq 'SomeValue')

) -or

(MemberOfGroup -eq 'CN=YourGroup,OU=Groups,DC=domain,DC=com')

) -and

(-not(Name -like 'SystemMailbox{*')) -and

(-not(Name -like 'CAS_{*')) -and

(-not(RecipientTypeDetailsValue -eq 'MailboxPlan')) -and

(-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and

(-not(RecipientTypeDetailsValue -eq 'PublicFolderMailbox')) -and

(-not(RecipientTypeDetailsValue -eq 'ArbitrationMailbox')) -and

(-not(RecipientTypeDetailsValue -eq 'AuditLogMailbox')) -and

(-not(RecipientTypeDetailsValue -eq 'AuxAuditLogMailbox')) -and

(-not(RecipientTypeDetailsValue -eq 'SupervisoryReviewPolicyMailbox'))

"

1

u/PinchesTheCrab Nov 18 '25

Tell it to convert the -not (...) statements to -notlike and -neq statements, and to also remove unnecessary parentheses for single conditions