Forum Discussion

Corin_R's avatar
Corin_R
Copper Contributor
Mar 06, 2024

How to change or force parameters from a dynamic distribution group filter using PowerShell

Hi All,

 

I've been trying to update the filter for our dynamic distribution groups. What I wanted to do was add a parameter saying that if someone has a Department of "Service", they should not appear in the DDG.

 

Here's what I started with:

 

((((Company -eq 'Contractors UK') -and (RecipientType -eq 'UserMailbox'))) -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(RecipientTypeDetailsValue -eq 'GuestMailUser')))

 

I want to add

 

-and (-not(Department -eq 'Service'))

 

So I ran this command in PowerShell:

 

Set-DynamicDistributionGroup -identity “UK Contractors” -RecipientFilter “((((Company -eq 'Contractors UK') -and (RecipientType -eq 'UserMailbox'))) -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(RecipientTypeDetailsValue -eq 'GuestMailUser')) -and (-not(Department -eq 'Service')))

 

thinking that as it's a Set... command, it would set the filter - it would need the the whole of the filter including the new parameter, you know, like when adding a parameter to the path in DOS using the Path command, you need to include the existing path as well as the new parameter, otherwise you're going to lose the existing path parameters, and only have the new one.

 

I didn't know that Set-DynamicDistributionGroup was additive, and didn't know about the -WhatIf argument.

 

So now the filter reads

 

((((((((((((((((((((((((((Company -eq 'Contractors UK') -and (RecipientType -eq 'UserMailbox')))

-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(RecipientTypeDetailsValue -eq 'GuestMailUser')))) -and (-not(Department -eq 'Service')))) -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')))

 

It's doubled up on everything except "-and (-not(Department -eq 'Service'))" , and there are loads of brackets!

 

Is there a way I can remove the unnecessary parameters without deleting and re-creating the DDG, or is there an argument I can use that will force a specific filter?

 

Many thanks

 

Corin

No RepliesBe the first to reply

Resources