Pages

Thursday, December 29, 2022

Bulk Create Distribution Lists (DL) in Microsoft O365 With Powershell

Recently due to an O365 tenant to tenant migration, we wanted to create distribution lists that were on tenant A, on tenant B. Creating a single distribution list with number of users in M365 admin center alone is a cumbersome task. As per our requirement, DL count is more than 100 with some have more than 50 users as members.

In a scenario like this, Powershell and Excel are your friends. I will explain how I achieved the goal.

1. Initial step is to create a CSV with required details. I received the DL details as below,  which is not the optimal for a csv.

 

2. I used "TEXTJOIN" Excel function to get users in multiple rows to a single row separated by a comma (,).

 

3. Then I created below CSV file with columns to add Name, Description, ManagedBy (Owner), PrimarySmtpAddress, Members in one go. Keep the Type as Distribution.


4. Next step is to connect to Exchange Online powershell by an administrator powershell console. Type

 Connect-ExchangeOnline

 

5. Once authenticated for the session, type below PS command line to bulk create DLs as per the previously created CSV. In here I have used the parameter "RequireSenderAuthenticationEnabled" as false to allow both internal and external users to send emails to these created DLs.

Import-CSV “D:\scripts\book1.csv” | ForEach-Object {New-DistributionGroup -Name $_.name `
-Description $_.Description -Type $_.Type -ManagedBy $_.ManagedBy `
-PrimarySmtpAddress $_.PrimarySmtpAddress -RequireSenderAuthenticationEnabled $false `
-Members $_.Members.Split(',')}

 

 

No comments:

Post a Comment