Exchange Online Distribution List Migration Script

Here is a short little script to migrate an Exchange Online distribution list from one tenant to a new one.

#Connect with source tenant
Connect-AzureAD
#Connect with destination tenant
Connect-ExchangeOnline
$DL = "distrobutionlist1","distrobutionlist2"
$SourceDomain = "alexholmeset.blog"
$DestinationDomain = "contoso.com"
foreach($D in $DL){
$List = @()
$List = Get-AzureADGroup -SearchString "$D"
$ListMembers = @()
$ListMembers = Get-AzureADGroupMember -ObjectId $List.ObjectId
$ListMembersUPN = @()
$ListMembersUPN = $ListMembers.UserPrincipalName
New-DistributionGroup -Name $List.DisplayName -Description $List.Description -PrimarySmtpAddress $($List.MailNickName+"@$DestinationDomain")
foreach($ListMemberUPN in $ListMembersUPN){
Add-DistributionGroupMember -Identity $List.DisplayName -Member $ListMemberUPN.replace("$SourceDomain","$DestinationDomain")
}
}
view raw DLMigration.ps1 hosted with ❤ by GitHub

One thought on “Exchange Online Distribution List Migration Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s