I'm working in an Exchange 2019 hybrid environment and I have several dynamic distribution lists (DDL) set up. I'm looking for guidance on how to add an extra custom attribute to my existing DDL rules and possibly include a security group in the process. I know the command to use is **Set-DynamicDistributionGroup**, but I find the current filter very confusing and I'm struggling to figure out where to make my additions. It seems like this filter was created a long time ago and I'm not sure how to simplify it to suit my needs.
4 Answers
You can use `Get-DynamicDistributionGroupMember` to see the DDL's current members, which might help you verify if your rules are working as intended. You can run something like this:
`$FTE = Get-DynamicDistributionGroup "Full Time Employees"
Get-Recipient -RecipientPreviewFilter $FTE.RecipientFilter -OrganizationalUnit $FTE.RecipientContainer` It's a good way to check what users are included based on your current filter.
If it seems overwhelming, maybe throw the filter into a tool like Copilot or another LLM to help parse it out. I tried it, and it really cleared things up for me. After running it through, I got a much clearer version that showed me where to add the new attributes I needed.
It sounds like you're dealing with a complex filter! One thing you could do is preview the DDL and recreate the rule to make it easier to read. Simplifying the filter will help a lot; try to remove some of the unnecessary parentheses. Start by outlining what you really need for your filter, focusing on user definitions without all the extra notations. Take a look at your existing parameters, and see if you can make a clean version of it.
I recommend getting rid of some of those `-not(...)` statements. It just complicates the readability. Here’s a simplified version you could start with:
`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'))` This should help clarify things for you!

I tried using it, and it at least hinted at where I could add my extra details. Here’s what it suggested for the command:
`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'))"` Not sure if it’s perfect, but it’s a start!