How to migrate Distribution Groups from Exchange on-premises to Exchange Online

Sarah Nmachi
3 min readJul 17, 2020

--

The suggested method to migrate distribution groups from the exchange on-premises to exchange online is to remove the object from on-premises and recreate it in exchange online.

This article is about using PowerShell to remove the distribution group in bulk and creating the same group in exchange online.

Just as with any script, you should test carefully and make edits necessary to suit your deployment.

Before making any changes, I prefer to export all distribution groups with all properties and save as a backup using the below cmdlet.

Get-DistributionGroup -ResultSize Unlimited |Format-List > C:\Users\sarah\Desktop\backup.csv

Step 1

Export the on-prem Distribution Groups with all the attributes to .csv

#Get distribution list

Get-distributiongroup -ResultSize Unlimited |Select Name, Primarysmtpaddress|Export-csv C:\Users\Sarah\Desktop\list.csv

#Get managedby:

The ManagedBy parameter specifies an owner for the group

Get-distributiongroup -ResultSize Unlimited | Select-object Name, Primarysmtpaddress ,@{label=”ManagedBy”;expression={[string]($_.managedby | foreach {$_.tostring().split(“/”)[-1]})}} |Export-csv C:\Users\Sarah\Desktop\managedBy.csv

#Get members

To export the members, I suggest you get the PowerShell script written by Tom Menezes made available in this link. Copy the text from the link below to notepad then save it as a .ps1 file.

To gather information on your distribution lists, run the following script from the Microsoft Exchange management console on your exchange on-premise. Usage is C:\Users\sarah\Desktop\GetMembers.ps1 and then select option 2 to export to a CSV file.

#Get other properties

Get-distributiongroup -ResultSize Unlimited | select name, Primarysmtpaddress,RequireSenderAuthenticationEnabled, MemberJoinRestriction, MemberDepartRestriction |Export-csv C:\Users\Sarah\Desktop\properties.csv

Step 2

Moved the DGs from sync OU to an Unsync OU to ensure the Synced DGs no longer show in office 365.

In my case, I moved the groups to the lost and found OU and force a sync. This step can be skipped if your distribution group is only visible on-premises.

#Move to lost and found OU

$TargetOU = “CN=LostAndFound,DC=sarahdomain,DC=local”

$Users = Import-Csv “ C:\Users\Sarah\Desktop\list.csv”

$Guids = ForEach ($User In $Users){ (Get-adGroup -Identity $User.Name).ObjectGUID }

Foreach($guid in $Guids ){Move-ADObject -Identity $guid.Guid -TargetPath $TargetOU}

Step 3

Import the DGs to Exchange Online.

#Connect to Exchange Online

Set-ExecutionPolicy RemoteSigned

Install-Module -Name ExchangeOnlineManagement

Connect-ExchangeOnline

#Create the distribution groups in exchange online

Import-CSV “ C:\Users\Sarah\Desktop\list.csv “ | foreach{

New-DistributionGroup -Name $_.Name -PrimarySmtpAddress $_. PrimarySmtpAddress -Type “Distribution” }

#Add members

Import-CSV “C:\Users\Sarah\Desktop\Members.csv” | foreach{Add-DistributionGroupMember -Identity $_.”Distribution Group Primary SMTP address” -Member $_.”Primary Smtp Address”}

#Add owners

Import-CSV “ C:\Users\Sarah\Desktop\managedBy.csv “| foreach{Set-DistributionGroup -Identity $_.PrimarySMTPAddress -ManagedBy $_.Managedby}

#Add other properties imported from the exchange on-premises.

Import-CSV “ C:\Users\Sarah\Desktop\properties.csv “| foreach{Set-DistributionGroup -Identity $_.PrimarySmtpAddress -RequireSenderAuthenticationEnabled $($_.RequireSenderAuthenticationEnabled -eq ‘true’) -MemberJoinRestriction $_.MemberJoinRestriction -MemberDepartRestriction $_.MemberDepartRestriction}

Now you have your on-premises Distribution groups migrated to Exchange Online with the same properties.

I hope this was informative and thank you for reading. If you have any questions please leave a comment below.

--

--

Responses (4)