How to Export Distribution Lists from on-premises Exchange and import to Exchange Online Office 365

How to export the distribution lists from the on-premises server

Exporting Distribution Lists

I am describing the steps I have taken to migrate the distribution lists from my on-premises server to my Office 365 Exchange online.
You can choose to export the files to different paths it is up to you. However, this guide will be described using the paths I used.

Create a folder on the C drive called Scripts
Run the following command your on-premises server Exchange Management Console.

The command will export the distribution lists only.

Get-DistributionGroup | select-object Name, PrimarySMTPAddress, grouptype | export-csv c:\scripts\distributionlists.csv

Exporting Distribution Lists Memberships

Copy the text from the link below to notepad then save it as DistributionGroupMemberReport.ps1


To gather information on your distribution lists, run the following script from Microsoft Exchange management console on your source server.
Usage is .\DistributionGroupMemberReport.ps1 and then select option 2 to export to a csv

When running the script you will see this.

Open the CSV generated above, and rename Primary SMTP address to PrimarySMTPaddress and Distribution Group to DistributionGroup.
Save it to c:\scripts\distributionlistmembers.csv

How to import the exported Distribution Lists to Exchange online

Copy the text from the link below to notepad then save it as distributionlists.ps1 on C:\scripts\


Open PowerShell, and connect it to Office365

Enter your Office 365 Global credentials

$LiveCred = Get-Credential

Create your Office 365 Session

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection

Import the above session

Import-PSSession $Session

Run the script you created above:   C:\scripts\distributionlists.ps1 it will import the distribution lists to Exchange online

Populating Distribution Lists membership

Import-Csv c:\scripts\distributionlistmembers.csv | foreach {Add-DistributionGroupMember -Identity $_.DistributionGroup -Member $_.PrimarySMTPaddress}

Now you have your on-premises Distribution lists migrated to Office 365 Exchange Online

Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the following command.

Remove-PSSession $Session

I just have followed the steps below and created this guide and it works well, if you have any questions please leave a comment below.

If you like it please click on the like button

If you wish to receive updates of new posts please like our page on Facebook.