We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Dynamic distribution list members

February 24, 2021 Views: 3361

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.

Parameters:

  • $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
PowerShell
$exchangeServer = "exchangeserver.domain.com" # TODO: modify me
$csvFilePath = "\\SERVER\share\members.csv" # TODO: modify me
$propertiesToExport = @("DisplayName", "Identity", "Alias", "EmailAddresses") # TODO: modify me. If $NULL - return all properties

try
{
    # 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
}
finally
{
    # Release resources
    if ($session) { Remove-PSSession $session }
}

Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers