MSExchangeGuru.com

Learn Exchange the Guru way !!!

 

Create Dynamic distribution Groups in Exchange 2016

Let’s take a look at how to create Query based Dynamic Distribution groups in Exchange 2016

To create Dynamic Distribution Groups in Exchange 2016 use the following Script:

###########################

$DDL = “Marketing Team – CHI”

$Alias = “CHI-Mktg”

# $Members –Specify the OU where the DDL members will be queried from who will be end up being members of the DDL group

$Members = “MSExchangeGuru.local/Management/Chicago”

# $OU – Specify the OU where the DDL will be residing in ActiveDirectory

$OU = “MSExchangeGuru.local/Company/DL/Chicago”

# Below are several cmdlet’s you can use, you will be choosing the one which fits your requirement.

# This cmdlet will create a plain vanilla DDL which will contain all AD objects from $Members

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((HiddenFromAddressListsEnabled -eq $false))} -RecipientContainer $Members

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((HiddenFromAddressListsEnabled -eq $false))} -RecipientContainer $Members

# This cmdlet will create a DDL with UserMailboxes ONLY from the OU $Members

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((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’)))} -RecipientContainer $Members

# This cmdlet will create a DDL with UserMailboxes from the OU $Members who match – (StreetAddress containing the number “99”, (for example 99 Sims Rd) + the condition of Office location containing the word “East”, for example East Granby)

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((RecipientType -eq ‘UserMailbox’) -and (-not(Name -like ‘SystemMailbox{*’)) –and ((StreetAddress -like ’99*’) –and (Office -like ‘East*’)) -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’)))} -RecipientContainer $Members

To give you an idea on how to play with RecipientFilter to include other AD attributes, let’s look at how to amend the one we used.

For example, I in the current RecipientFilter I added –and ((StreetAddress -like ’99*’) –and (Office -like ‘East*’)) right after ‘SystemMailbox{*’))

As shown:

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((RecipientType -eq ‘UserMailbox’) -and (-not(Name -like ‘SystemMailbox{*’)) –and ((StreetAddress -like ’99*’) –and (Office -like ‘East*’)) -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’)))} -RecipientContainer $Members

You can edit this to include something like: –and ((Title -like ‘Analyst*’ –or Title –like ‘Engineer*’) –and (StateOrProvince -eq ‘CH’))

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((RecipientType -eq ‘UserMailbox’) -and (-not(Name -like ‘SystemMailbox{*’)) –and ((Title -like ‘Analyst*’ –or Title –like ‘Engineer*’) –and (StateOrProvince -eq ‘CH’)) -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’)))} -RecipientContainer $Members

Include something like –and ((Title -like ‘Analyst*’ –or Title –like ‘Engineer*’) –and (StateOrProvince -eq ‘CH’)) –and (CustomAttribute1 -eq ‘CHI’)

New-DynamicDistributionGroup -Name $DDL -Alias $Alias -OrganizationalUnit $OU -RecipientFilter {((RecipientType -eq ‘UserMailbox’) -and (-not(Name -like ‘SystemMailbox{*’)) –and ((Title -like ‘Analyst*’ –or Title –like ‘Engineer*’) –and (StateOrProvince -eq ‘CH’)) –and (CustomAttribute1 -eq ‘CHI’) -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’)))} -RecipientContainer $Members

So in essence, you can keep building on RecipientFilter query till you have the desired outcome

# Now finally to Query members of the DDL use this powershell script

Get-DynamicDistributionGroup $DDL | ForEach {Get-Recipient -RecipientPreviewFilter $_.RecipientFilter -OrganizationalUnit $_.RecipientContainer} | Select DisplayName,PrimarySMTPAddress | Format-Table

Or Run this cmdlet to simply count the number of users in the DDL

Get-DynamicDistributionGroup $DDL | ForEach {Get-Recipient -RecipientPreviewFilter $_.RecipientFilter -OrganizationalUnit $_.RecipientContainer} | Measure-Object

###########################

Please leave a comment with your questions and queries you create for Exchange 2016 Dynamic Distribution Groups so it will help others.

Ratish Nair

Microsoft MVP

Team @MSExchangeGuru.com

Leave a Reply

ad

Categories

Archives