Script Repository

Dynamic distribution list members

February 24, 2021

The script creates a CSV-formatted report on members of a dynamic distribution list.

To generate such a report on request, you can create a custom command that runs the script on Ms-Exch-Dynamic-Distribution-List objects. For this purpose, on Step 2 of the Create Custom Command wizard, select Show all object types and Ms-Exch-Dynamic-Distribution-List.


  • $exchangeServer - Specifies the fully qualified domain name (FQDN) of your Exchange Server.
  • $csvFilePath - Specifies a full path to the CSV file containing the report.
  • $propertiesToExport - Specifies properties of the members to include in the report.
Edit Remove
$exchangeServer = "" # TODO: modify me
$csvFilePath = "\\SERVER\share\members.csv" # TODO: modify me
$propertiesToExport = @("DisplayName", "Identity", "Alias", "EmailAddresses") # TODO: modify me. If $NULL - return all properties

    # Create a remote PowerShell session to the Exchange Server
    $session = New-PSSession -configurationname Microsoft.Exchange -connectionURI http://$exchangeServer/PowerShell
    Import-PSSession $session -DisableNameChecking -AllowClobber
    # Get the dynamic distribution group
    $group = Get-DynamicDistributionGroup -Identity "%distinguishedName%"
    # Get members
    $members = Get-Recipient -RecipientPreviewFilter $group.RecipientFilter -OrganizationalUnit $group.RecipientContainer

    if ($propertiesToExport -ne $NULL)
        $members = $members | Select -Property $propertiesToExport
    # Export report
    $members | Export-Csv -NoTypeInformation -Path $csvFilePath
    # Release resources
    if ($session) { Remove-PSSession $session }

Comments ( 0 )
No results found.
Leave a comment