#PSTip How to create a dynamic distribution group

Note: This tip requires PowerShell 2.0 or above.

One of the group types that Exchange can create is a dynamic distribution group. Unlike regular distribution groups that contain a defined set of members, the membership list for dynamic distribution groups is calculated each time a message is sent to the group, based on the filters and conditions that you define.  When an email message is sent to a dynamic distribution group, it is delivered to all recipients in the organization that match the criteria defined for that group.

To create a dynamic distribution group use the New-DynamicDistributionGroup cmdlet. This example creates a dynamic distribution that contains only mailbox users from the Users OU.

PS> New-DynamicDistributionGroup -IncludedRecipients MailboxUsers -Name MailboxUsersDDG -OrganizationalUnit Users

This example creates a dynamic distribution group, ITUsers, with a custom recipient filter. It contains all mailbox users from the Users OU who are members of the Computers department.

PS> $itUsers = New-DynamicDistributionGroup -Name ITUsers -RecipientFilter {RecipientType -eq 'UserMailbox' -and Department -eq 'Computers'} -OrganizationalUnit Users
PS> $itUsers | fl *filter

RecipientFilter     : ((((RecipientType -eq 'UserMailbox') -and (Department -eq 'Computers'))) -and (-not(Name -like 'S
                      ystemMailbox{*')) -and (-not(Name -like 'CAS_{*')) -and (-not(RecipientTypeDetailsValue -eq 'Mail
                      boxPlan')) -and (-not(RecipientTypeDetailsValue -eq 'DiscoveryMailbox')) -and (-not(RecipientType
                      DetailsValue -eq 'ArbitrationMailbox')))
LdapRecipientFilter : (&(objectClass=user)(objectCategory=person)(mailNickname=*)(msExchHomeServerName=*)(department=Co

In the next tip we will see how to list the members of the dynamic distribution group. Stay tuned.

Filed in: Columns, Tips and Tricks Tags: , , ,

14 Responses to "#PSTip How to create a dynamic distribution group"

  1. yOn says:

    Question here: what command to filter 2 cities? Command like: New-DynamicDistributionGroup -Name “Funeral Home Managers ON” -RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and (Title -like ‘Director*’ -or Title -like ‘Manager*’) -and (StateOrProvince -eq ‘ON’) -or (City -eq ‘Toronto’, ‘Alberta’}. Basically, what im trying to achieve is, when users sends email to DynamicDL “Funeral Home Managers ON”, only managers from ON and City of Toronto and Alberta will be able to receive. Please advise.

    • ShayLevy says:

      Give this filter a try:

      (RecipientType -eq ‘UserMailbox’) -and
      (Title -like ‘Director*’ -or Title -like ‘Manager*’) -and
      (StateOrProvince -eq ‘ON’) -and (City -eq ‘Toronto’ -or City -eq ‘Alberta’)

      • yOn says:

        Thanks for your quick response. I’ve tried that but I only see users in toronto when i hit Preview under Filter tab. please help.

        • ShayLevy says:

          I suggest you start with a minimal filter and add to it once it matches your expectations. First start with:

          (RecipientType -eq ‘UserMailbox’) -and
          (City -eq ‘Toronto’ -or City -eq ‘Alberta’)

          Do you get users from both cities?

          • yOn says:

            I created 4 users, 2 in toronto and 2 in alberta and after i issued that command, I refresh it and checked the preview and I only see toronto users. please help

          • ShayLevy says:

            Do you get all 4 users with this?

            Get-Recipient -RecipientPreviewFilter {RecipientType -eq ‘UserMailbox’ -and City -eq ‘toronto’ -or City -eq ‘alberta’}

          • yOn says:

            Well I get all users under those mentioned cities.

          • ShayLevy says:

            Now try the same filter for the DG. Do you get the same result?

          • yOn says:

            sorry but it didn’t work. This is what im trying to achieve. When we send users to .TEST (TEST) Dynamic DL, we want all have titles of Funeral Home Manager under the Province of ON and the City of (please see below command)

            New-DynamicDistributionGroup -Name “.TEST (TEST)” -OrganizationalUnit “domain.ca/Groups”-RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and (Title -eq ‘Funeral Home Manager’) -and (StateOrProvince -eq ‘ON’) -and (City -eq ‘Amherst’) -or (City -eq ‘Dartmouth’)}

            I know you gave me the command of:

            New-DynamicDistributionGroup -Name “.TEST (TEST)” -OrganizationalUnit “domain.ca/Groups”-RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and (Title -eq ‘Funeral Home Manager’) -and (StateOrProvince -eq ‘ON’) -and (City -eq ‘Amherst’ -or City -eq ‘Dartmouth’)}

            It accepted the command but it only filters all the users under City of Amherst, and I dont know why. I checked the title and its correct. Please help

          • ShayLevy says:

            Check the Filter tab of the group, make sure the recipient container is applied to the one you choose and that users from all cities reside under that container. I just checked in my environment and I didn’t have problems getting users from both cities.

          • yOn says:

            Sorry, i meant it worked but it sees/filters all the users even though they’re not managers, as my command says that only managers in that city can receive emails..

  2. Chris says:

    Hey – this forum has been such a help.

    i have a question. I can’t for the life of me add additional AD users do the DDG’s we have in our organisation, via Powershell / or Exchange Mgmt Shell.

    I can successfully run:
    >$members = Get-DynamicDistributionGroup -Identity “Group Name” ……… then
    >Get-Recipient -RecipientPreviewFilter $members.RecipientFilter to produce a list of members on the Group….

    However when I try and run:
    >Add-DistributionGroupMember -Identity “Group Name” -Member “first.last@domain.com.au” it tells me object “group name” couldn’t be found – when it could above producing the list of names.

    My question. Can and if so, how, can additional members be added to DDGs?

Leave a Reply

Submit Comment

© 2018 PowerShell Magazine. All rights reserved. XHTML / CSS Valid.
Proudly designed by Theme Junkie.
%d bloggers like this: