Export Distribution groups

Rising Flight 4,516 Reputation points
2022-03-31T03:32:06.11+00:00

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

DisplayName,PrimarySMTPAddress,managedby,Description

$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.
4,517 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,626 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,261 Reputation points
    2022-04-01T01:29:20.387+00:00

    @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 4,516 Reputation points
    2022-04-01T00:15:50.497+00:00

    i tried the above syntaxes but i am not getting output

    0 comments No comments

  2. Rising Flight 4,516 Reputation points
    2022-04-01T21:23:47.457+00:00

    Thanks Kyle

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


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.