13

#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
                      mputers)(!(name=SystemMailbox{*))(!(name=CAS_{*))(!(msExchRecipientTypeDetails=16777216))(!(msExc
                      hRecipientTypeDetails=536870912))(!(msExchRecipientTypeDetails=8388608)))

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: , , ,

2 Pingbacks/Trackbacks

  • Pingback: Microsoft Most Valuable Professional (MVP) – Best Posts of the Week around Windows Server, Exchange, SystemCenter and more – #46 - Dell TechCenter - TechCenter - Dell Community

  • Pingback: Eskchi

  • yOn

    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

      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

        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

          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

            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

            Do you get all 4 users with this?

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

          • yOn

            Well I get all users under those mentioned cities.

          • ShayLevy

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

          • yOn

            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

            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

            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..

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