Forum Discussion
Curious_Kevin16
Jun 11, 2023Iron Contributor
Export DL Memberships from Exchange 2013 and Import to 365 via PowerShell
Hi Guys, I am migrating our Distribution lists from Exchange 2013 server to O365. I have the following script to export and import memberships to a SINGLE DL but seeking your kind help to do the...
AndySvints
Jun 13, 2023Iron Contributor
Hello Curious_Kevin16,
Script provided by elieelkarkafi is for exporting data from M365 and will not fit directly to your use case.
In your case logic is pretty straight forward:
Exchange Server
1. Get All Distribution Lists
2. For each group export Members
M365
1. For each Exchange server DL get exported members
2. Foreach member add him/her to DL in M365
Example code:
#Exchange Server
$DistributionList=Get-DistributionGroup
foreach($dl in $DistributionList){
Get-DistributionGroupMember -Identity $dl.Name | Export-CSV -Path "C:\Temp\$($dl.Name)-DLMembers.csv"
}
#M365
#Connect to Exchange Online
$DistributionList=Get-ChildItem -Path "C:\Temp" -Filter "*-DLMembers.csv"
foreach($dl in $DistributionList){
$Memberships = Import-Csv -Path $($dl.Name)-DLMembers.csv"
foreach($m in $Membership){
Add-DistributionGroupMember -Identity $dl.Name -Member $m.PrimarySmtpAddress
}
}
Please note that this sample code will not handle expanding group which is a member of another group.
Hope that helps.