Forum Discussion
Dynamic Distribution List based on multiple AAD fields
- Jan 15, 2021
Cris20 Vasil prompted me to look at this request. This code worked for me...
$Filter = "((Title -like 'Architect') -and (ExchangeUserAccountControl -ne 'AccountDisabled'))"
New-DynamicDistributionGroup -Name "Architects" -DisplayName "System and Engineering Architects" -Alias AllArchitects -PrimarySmtpAddress Architects@Office365itpros.com -RecipientFilter $Filter
Set-DynamicDistributionGroup -Identity AllArchitects -ManagedBy Tony.Redmond -MailTip "Distribution List for anyone with Architect in the job title"
TR
Thank you. It worked!
I had to chain multiple conditions for the filter because, from what I've read, wildcards can't be used as first character in RecipientFilter.
I have many job titles like Architect (Junior Architect, Lead Architect, Senior Architect, etc), a few variations for Associate and for Partner and I need to include all in filter. I tried "Title -like '*Architect' -or Title -like '*Associate' -or Title -like '*Partner'", but got an error.
Is there a more elegant solution than a dozen of -or conditions?
Cris20 Unfortunately, you'll have to include multiple conditions, which is what I did when I wrote the problem up:
How to Create Exchange Dynamic Distribution List with Custom Recipient Filters
Exchange dynamic distribution lists allow messages to be sent to sets of recipients determined by a query against the directory. A custom filter is a powerful way to find the right set of recipients. In this case, we want to find mailboxes with certain job titles whose Azure AD accounts are not blocked for sign-in. Here’s how to create the filter, make sure it works, and create the DDL.