Export All Distribution Lists and Members using PowerShell

Export All Distribution Lists and Members using PowerShell

To export all distribution groups and their members to a CSV file, use the following PowerShell script:

 

Please refer to:

www.sharepointdiary.com/2022/03/office-365-export-distribution-list-members-to-csv-using-powershell.html#ixzz84o8q4E3v

 

 

#Read more: www.sharepointdiary.com/2022/03/office-365-export-distribution-list-members-to-csv-using-powershell.html#ixzz84o9taRMB

 

Copy to notepad and Rename file to  ExportDistributionList.ps1 and run in powershell.

#Parameters

$CSVFilePath = “C:\Temp\DL-Members.csv”

Try {

    #Connect to Exchange Online

    Connect-ExchangeOnline -ShowBanner:$False

    #Get all Distribution Lists

    $Result=@()  

    $DistributionGroups = Get-DistributionGroup -ResultSize Unlimited

    $GroupsCount = $DistributionGroups.Count

    $Counter = 1

    $DistributionGroups | ForEach-Object {

        Write-Progress -Activity “Processing Distribution List: $($_.DisplayName)” -Status “$Counter out of $GroupsCount completed” -PercentComplete (($Counter/$GroupsCount)*100)

        $Group = $_

        Get-DistributionGroupMember -Identity $Group.Name -ResultSize Unlimited | ForEach-Object {

            $member = $_

            $Result += New-Object PSObject -property @{

            GroupName = $Group.Name

            GroupEmail = $Group.PrimarySmtpAddress

            Member = $Member.Name

            EmailAddress = $Member.PrimarySMTPAddress

            RecipientType= $Member.RecipientType

            }

        }

    $Counter++

    }

    #Get Distribution List Members and Exports to CSV

    $Result | Export-CSV $CSVFilePath -NoTypeInformation -Encoding UTF8

}

Catch {

    write-host -f Red “Error:” $_.Exception.Message

}

 

 

#Read more: www.sharepointdiary.com/2022/03/office-365-export-distribution-list-members-to-csv-using-powershell.html#ixzz84o9nxKvH

 

Kon Belieu

Tags:

Comments are closed

Latest Comments

No comments to show.