Get-DistributionGroup-UnifiedGroup

Roger Roger 6,691 Reputation points
2025-01-18T08:40:11.4266667+00:00

Hi All,

I am using an Exchange hybrid environment. I have over 50,000 distribution lists, 40,000 unified groups, and 7,000 mail-enabled security groups.

I want to export their Names, Display Names, Primary SMTP addresses, Aliases, and Descriptions to a CSV file. My requirement is to export:

  • All distribution lists and mail-enabled security groups from both Exchange Online and Exchange on-premises.
  • Unified groups in Exchange Online.

For Exchange Online distribution lists, I would also like to export the sync status to determine whether the list is an on-premises or online distribution list. Please guide me with the PowerShell syntax.

Microsoft Exchange Online
Exchange Server
Exchange Server
A family of Microsoft client/server messaging and collaboration software.
1,422 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,702 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,775 questions
Microsoft Exchange Hybrid Management
Microsoft Exchange Hybrid Management
Microsoft Exchange: Microsoft messaging and collaboration software.Hybrid Management: Organizing, handling, directing or controlling hybrid deployments.
2,210 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alex Zhang-MSFT 3,940 Reputation points Microsoft Vendor
    2025-01-20T05:44:05.7233333+00:00

    Hello, @Roger Roger,

    Welcome to the Microsoft Q&A platform!

    Based on your requirements, exporting such data from both on-premises Exchange and Exchange Online involves using the Exchange Management Shell (EMS) for on-premises Exchange and the Exchange Online PowerShell module for Exchange Online.

    Below are the steps and scripts to help you export the required information:

    1. Export Distribution Lists and Mail-Enabled Security Groups from Exchange On-Premises by using Exchange Management Shell
    Get-DistributionGroup -ResultSize Unlimited | Select-Object Name, DisplayName, PrimarySmtpAddress, Alias, Description | Export-Csv -Path "C:\temp\OnPrem_DistributionGroups.csv" -NoTypeInformation
    >> Get-DistributionGroup -ResultSize Unlimited -RecipientTypeDetails MailUniversalSecurityGroup | Select-Object Name, DisplayName, PrimarySmtpAddress, Alias, Description | Export-Csv -Path "C:\temp\OnPrem_MailEnabledSecurityGroups.csv" -NoTypeInformation
    

    User's image

    1. Export Distribution Lists, Mail-Enabled Security Groups, and Unified Groups from Exchange Online by using Windows PowerShell
    Connect-ExchangeOnline
    
    Get-DistributionGroup -ResultSize Unlimited | Select-Object Name, DisplayName, PrimarySmtpAddress, Alias, Description, @{Name="SyncStatus";Expression={if ($_.IsDirSynced) {"Synced"} else {"Cloud"}}} | Export-Csv -Path "C:\temp\Online_DistributionGroups.csv" -NoTypeInformation
    >> Get-DistributionGroup -ResultSize Unlimited -RecipientTypeDetails MailUniversalSecurityGroup | Select-Object Name, DisplayName, PrimarySmtpAddress, Alias, Description | Export-Csv -Path "C:\temp\Online_MailEnabledSecurityGroups.csv" -NoTypeInformation
    
    Get-UnifiedGroup -ResultSize Unlimited | Select-Object Name, DisplayName, PrimarySmtpAddress, Alias, Description | Export-Csv -Path "C:\temp\Online_UnifiedGroups.csv" -NoTypeInformation
    
    Disconnect-ExchangeOnline -Confirm:$false
    
    1. Combine the CSV Files by using Windows PowerShell
    $OnPremDGs = Import-Csv -Path "C:\temp\OnPrem_DistributionGroups.csv"
    $OnPremMESGs = Import-Csv -Path "C:\temp\OnPrem_MailEnabledSecurityGroups.csv"
    $OnlineDGs = Import-Csv -Path "C:\temp\Online_DistributionGroups.csv"
    $OnlineMESGs = Import-Csv -Path "C:\temp\Online_MailEnabledSecurityGroups.csv"
    $OnlineUGs = Import-Csv -Path "C:\temp\Online_UnifiedGroups.csv"
    
    $AllGroups = $OnPremDGs + $OnPremMESGs + $OnlineDGs + $OnlineMESGs + $OnlineUGs
    $AllGroups | Export-Csv -Path "C:\temp\All_Groups.csv" -NoTypeInformation
    

    User's image

    Command test results

    User's image

    This will give you a single CSV file containing all the required information from both Exchange Online and Exchange on-premises.

    Should you need more help on this, you can feel free to post back. 


    If the answer is helpful, please click on “Accept answer” as it could help other members of the Microsoft Q&A community who have similar questions and are looking for solutions.

    Thank you for your support and understanding.

    Best Wishes,

    Alex Zhang

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.