Export Distribution groups

Rising Flight 3,121 Reputation points

Hi All

i want to export all my distribution group and unified groups list to a csv file. i want to export the below information. I want to try the below script and also how can i add description or notes in the script


$Groups = Get-DistributionGroup -ResultSize Unlimited  
foreach ($Group in $Groups){  
Get-DistributionGroup  -identity $Group.Name | select @{Name='Group'; Expression={$Group.Name}},Expression={$_.PrimarySmtpAddress}}, @{n = 'Owner'; e = {((Get-DistributionGroup $Group.Name).ManagedBy).name}}  
} | export-csv c:\list.csv -NoTypeInformation  

$Groups = Get-UnifiedGroup -ResultSize Unlimited  
foreach ($Group in $Groups){  
Get-UnifiedGroup  -identity $Group.Name | select @{Name='Group'; Expression={$Group.Name}},Expression={$_.PrimarySmtpAddress}}, @{n = 'Owner'; e = {((Get-UnifiedGroup $Group.Name).ManagedBy).name}}  
} | export-csv c:\groups.csv -NoTypeInformation  

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.
3,867 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,005 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,171 Reputation points

    @Rising Flight

    For Unified Group:

    $groups = Get-UnifiedGroup -ResultSize Unlimited  
    $Data = @()  
    foreach($group in $groups){  
        $Data += Get-UnifiedGroup $group.name | select DisplayName,PrimarySMTPAddress,Notes,managedby  
    $Data | Export-Csv C:\temp\unifiedgroups.csv -NoTypeInformation  

    For distribution group:

    $groups = Get-DistributionGroup -ResultSize Unlimited  
    $Data = @()  
    foreach($group in $groups){  
        $Data += Get-DistributionGroup $group.name | select DisplayName,PrimarySMTPAddress,Notes,managedby  
    $Data | Export-Csv c:\temp\DistributionLists.csv -NoTypeInformation  

    By the way, if the previous script was useful, I suggest you accept it as an answer to help more users. If it doesn't work, I suggest you continue the discussion under the previous post. Asking the same question multiple times is not good for other community members reading.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

2 additional answers

Sort by: Most helpful
  1. Rising Flight 3,121 Reputation points

    i tried the above syntaxes but i am not getting output

    0 comments No comments

  2. Rising Flight 3,121 Reputation points

    Thanks Kyle

    if i need owners information(managedby) as email address rather than display name. how do i get that information