Since Dynamic Distribution Group lists its members by running the query (to Get-Recipient command) whenever someone sends email to this DL. But how do we troubleshoot if a user is not receiving email from this DL. Why would this user left out? Exchange 2010 onwards Microsoft provided PowerShell is the only way to check the members of Dynamic DL. I am going to explain how to do it?
We are going to use the following commands:
Get-DynamicDistributionGroup and Get-Recipient.
First get the dynamic DL named DL-NorthAmerica and assigned to variable $dl.
$dl = Get-DynamicDistributionGroup “DL-NorthAmerica”
Next run the query and list the recipients and assigned to a variable $allr
$allr = Get-Recipient -RecipientPreviewFilter $dl.RecipientFilter -OrganizationalUnit $dl.RecipientContainer –ResultSize Unlimited
List all the recipients with any other information you want.
$allr | Select-Object Name,PrimarySmtpAddress,Title,Department,city
If you want you can save the results to a CSV file.
$allr | Select-Object Name,PrimarySmtpAddress,Title,Department,city | Export-Csv -Path “$pwd\ShoreTel-GlobalMembers.csv” –NoTypeInformation
Any questions, leave me reply, will respond.
hi Anand, This was very good article. However, I want to export members from 43 Dynamic distribution group into separate CSV files 43 csv files). Is it possible?
Absolutely, you can. Create a text file and type the first row as Name and type all of your 43 DL Names one for each line. Save the text file as DynamicDLList.csv. Copy past the script below to the same location and Execute the script in PowerShell after connecting to Exchange (or Exchange Online). It will create 43 CSV files with the member list.
$DLs = Import-Csv -Path .\DynamicDLList.csv
foreach($DL in $DLs)
{
$dl = Get-DynamicDistributionGroup $DL.Name
$allr = Get-Recipient -RecipientPreviewFilter $dl.RecipientFilter -OrganizationalUnit $dl.RecipientContainer –ResultSize Unlimited
$allr | Select-Object Name,PrimarySmtpAddress,Title,Department,city | Export-Csv -Path “.\$($DL.Name).csv” –NoTypeInformation
}
Awesome Anand. It works..thanks a lot for your help. You are best !!!
Thank You!!!!! Anand this was of great help.
Very helpful! Any hints on how I would adjust the above script to export those 43 dynamic distribution lists into one single workbook?
We have a main “All Employees” distribution list which contains 10 sub distribution lists for each office. Those sub distribution lists have a dynamic distribution list as their source. Assuming it isn’t easy to loop through the main distribution list, for all nested members, the next best thing would be for me to add the 10 dynamic distribution lists for each office to the DynamicDisctibutionList.csv and then export them all to the same workbook.
Rodriguez, Here is how you export all 43 DDL members in to one CSV file. I have modified to store the members of each DL in “DynamicDLList.csv” to “All-Users-from-all-DDLs.csv” file with -append option.
$DLs = Import-Csv -Path .\DynamicDLList.csv
foreach($DL in $DLs)
{
$dl = Get-DynamicDistributionGroup $DL.Name
$allr = Get-Recipient -RecipientPreviewFilter $dl.RecipientFilter -OrganizationalUnit $dl.RecipientContainer –ResultSize Unlimited
$allr | Select-Object Name,PrimarySmtpAddress,Title,Department,city | Export-Csv -Path .\All-Users-from-all-DDLs.csv –NoTypeInformation -Append
}
Hello Anand… I want to export all the Dynamic Distribution Group with members in below format
GroupDisplayName,GroupPrimarySMTPAddress,MemberDisplayname,MemberPrimarySMTPAddress,RecipientTypeDetails
I have a code that is working for Distribution group, However it is not working for Dynamic Distribution Group.
below is code
$results = @()
$DistributionGroups = Get-DynamicDistributionGroup -ResultSize Unlimited
$Group = @()
foreach($DistributionGroup in $DistributionGroups)
{
$GroupPrimarySMTPAddress = $DistributionGroup.PrimarySMTPAddress
$DisplayName = $DistributionGroup.DisplayName
#$DistributionGroupMembers = Get-DistributionGroupMember $DistributionGroup.name -ResultSize Unlimited
#we can use $DistributionGroup.PrimarySMTPAddress as well. However, we will error for groups which do not have PrimarySMTPAddress
$DistributionGroupMembers = Get-DynamicDistributionGroup $DistributionGroup.PrimarySMTPAddress
Get-Recipient -RecipientPreviewFilter $DistributionGroupMembers.RecipientFilter -OrganizationalUnit $DistributionGroupMembers.RecipientContainer
foreach($DistributionGroupMember in $DistributionGroupMembers)
{
$properties = @{
GroupDisplayName = $displayName
GroupPrimarySMTPAddress = $GroupPrimarySMTPAddress
MemberPrimarySMTPAddress = $DistributionGroupMember.PrimarySMTPAddress
MemberDisplayname = $DistributionGroupMember.DisplayName
RecipientTypeDetails = $DistributionGroupMember.RecipientTypeDetails
}
$results += New-Object psobject -Property $properties
}
}
$results | FT -AutoSize -Wrap GroupDisplayName,GroupPrimarySMTPAddress,MemberDisplayname,MemberPrimarySMTPAddress,RecipientTypeDetails
Many thanks! Came across your site with a Google search … it is a bookmark now.
This was really helpful! Quick question, how can I get other objects such as extensionAttributes or employeeType, etc. ? I have not been able to figured out.
Antonio: you can get those additional attributes using AD PoweShell module cmdlets. see example below: $allr has all recipients from the query by Get-Recipients cmdlet from the blog above.
foreach ($u in $allr)
{
$ua = Get-ADUser $u.SAMAccountName -Properties *
$ua.extentionAttributes1
$ua.employeeType
}
Hope you can figure out from here.
Hello Anand.. I was able to get it worked after modification as below..
$results = @()
$DistributionGroups = Get-DynamicDistributionGroup -ResultSize Unlimited
$Group = @()
foreach($DistributionGroup in $DistributionGroups)
{
$GroupPrimarySMTPAddress = $DistributionGroup.PrimarySMTPAddress
$DisplayName = $DistributionGroup.DisplayName
#$DistributionGroupMembers = Get-DistributionGroupMember $DistributionGroup.name -ResultSize Unlimited
#we can use $DistributionGroup.PrimarySMTPAddress as well. However, we will error for groups which do not have PrimarySMTPAddress
$FTE = Get-DynamicDistributionGroup $DistributionGroup.PrimarySMTPAddress
$DistributionGroupMembers = Get-Recipient -RecipientPreviewFilter $FTE.RecipientFilter -OrganizationalUnit $FTE.RecipientContainer
foreach($DistributionGroupMember in $DistributionGroupMembers)
{
$properties = @{
GroupDisplayName = $displayName
GroupPrimarySMTPAddress = $GroupPrimarySMTPAddress
MemberPrimarySMTPAddress = $DistributionGroupMember.PrimarySMTPAddress
MemberDisplayname = $DistributionGroupMember.DisplayName
RecipientTypeDetails = $DistributionGroupMember.RecipientTypeDetails
}
$results += New-Object psobject -Property $properties
}
}
$results | FT -AutoSize -Wrap GroupDisplayName,GroupPrimarySMTPAddress,MemberDisplayname,MemberPrimarySMTPAddress,RecipientTypeDetails