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 same for MULTIPLE DLs (200 in my case). Appreciate if anyone can shed some lights with a modified script here !
Export from Exchange Server 2013 for a single DL:
Get-DistributionGroupMember -Identity "Marketing USA" | select Name,Alias | Export-CSV -Path "C:\Temp\ExportedDLMembers.csv"
Import DL Membership from above CSV to Office 365 for a single DL:
$CSVPath = "C:\Temp\ExportedDLMembers.csv"
$Memberships = Import-Csv -Path $CSVPath
$Memberships | ForEach-Object {
$DistributionList = $_.Name
$Member = $_.PrimarySmtpAddress
Add-DistributionGroupMember -Identity $DistributionList -Member $Member
}
How can I achieve the same for MULTIPLE DLs (Export from Exchange server 2013 and import to 365 where Destination DLs are already exists). ?
Thank you so much !
Kev
2 Replies
Sort By
- AndySvintsSteel 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 M365Example 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.
- Please refer to the below link where you can download the full script
https://o365reports.com/2022/04/19/list-all-the-distribution-groups-a-user-is-member-of-using-powershell/