Migrating Distro Groups from Exchange to Office 365, part 4

In steps 4 and 5 of part one I wrote,

4. Delete on-premises groups. After verifying that I had all the data I needed to rebuild them in the cloud (or on-premises if necessary), I removed the original groups…

5. Rename and address online groups. I wrote a third PowerShell script (Address_DistroGroup.ps1) that renames the new online groups to the old on-premises group names and adds the email addresses extracted in step 1.

Let me repeat this: Be very careful on Step 4. Make sure that you have good data in your exported files and that you have a good backup before proceeding.

Migrate your Exchange distribution groups to Office 365

Once you’ve deleted the original on-premises groups and synced your on-premises directory to the cloud, connect to Exchange Online and run this script to apply the old on-premises group’s names and addresses to the online group:

# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# Filename: Address_DistroGroup.ps1
# Version: 	2016.03.31
# Purpose: Imports the email addresses of groups that were exported
# by the Export_DistroGroup.ps1 script.

# 
# Usage:
# Address_DistroGroup "Group Name"
# "Group Name" must be the exact name of the group in the on-premises
# Exchange organization and the on-premises group must already be
# deleted and the directory synced to Exchange Online.
# 

Param(
	[string]$Group
)

# Specify the path of your input files. This should be the same as
# the OutPath from Export_DistroGroup.
$InPath = "C:\Temp\Groups\"

# If the Completed folder doesn't exist, create it.
$CompletePath = $InPath + "Completed\"
if (-not (Test-Path $CompletePath)) {
	New-Item $CompletePath -Type Directory
}

# This tells the script where to find the list of addresses.
$AddressesFile = $InPath + $Group + "-Addresses.csv"

# Assumes that your original online group creation
# appended " OL" to the name of each group.
$OldName = $Group + " OL"

# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
if (Test-Path $AddressesFile) {
	# Adds the list of addresses to the online group.
	Write-Host "Adding group addresses..."
	$Addresses = Import-CSV $AddressesFile
	$Addresses | Foreach {
		if ($_.ProxyAddressString -like "smtp*") {
			Set-DistributionGroup $OldName `
			  -EmailAddresses @{add=$_.ProxyAddressString.toLower()}
		}
		elseif ($_.ProxyAddressString -like "X500*") {
			$X500addy = "x500:" + $_.AddressString
			Set-DistributionGroup $OldName `
			  -EmailAddresses @{add=$X500addy}
		}
	}
	
	# Renames the group from "Group Name OL" to "Group Name".
	Set-DistributionGroup $OldName -DisplayName $Group -Name $Group
	
	# Moves the address file to the "Completed" folder.
	Move-Item $AddressesFile -Destination $CompletePath
}

Do I have to say it again? Of course, not. You’re way too smart to need this. Unfortunately, somebody out there–we’re not saying who–might not be. Here it is: TEST and VERIFY. Don’t just trust me that this process will work. Check every line and test it first.

Part 1 – Overview of the process I used to migrate my Exchange distribution groups to Office 365.
Part 2 – Exporting your on-premises distro group settings to CSV files.
Part 3 – Importing your group settings from the CSV files to Exchange Online.
Part 4 – Renaming and addressing your online distro groups.
Part 5 – Rebuilding your Dynamic Distribution groups online.

[Update 4/1/2016 – Corrected code to properly handle X500 addresses and rename the group after addressing.]

Leave a Reply

Your email address will not be published. Required fields are marked *