🔧 New: User Management Graph PowerShell Toolkit

Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.

🚀 Launch Toolkit

Bulk Add Distribution Group Members (Exchange PowerShell)

Maintaining accurate and up-to-date Distribution Lists (DLs) is essential for effective communication within organizations. While Microsoft Graph PowerShell is a robust tool for managing Microsoft 365 Groups, it does not support bulk adding members to Distribution Lists. For that, you must use Exchange Online PowerShell.

In this article, we’ll walk through a script that bulk-adds members to DLs using a simple CSV file, ideal for onboarding or restructuring group memberships.


Script – Bulk Add Members to Distribution Lists

# Connect to Exchange Online
Connect-ExchangeOnline
                                
# Import CSV containing group-member mappings
$entries = Import-Csv -Path "C:\Users\Thilak\Downloads\dl_members.csv"
                                
foreach ($entry in $entries) {
    try {
        Add-DistributionGroupMember -Identity $entry.GroupName -Member $entry.MemberEmail
        Write-Host "Added $($entry.MemberEmail) to $($entry.GroupName)" -ForegroundColor Green
    } catch {
        Write-Warning "Failed to add $($entry.MemberEmail) to $($entry.GroupName): $_"
    }
}
                            

CSV Format Example (dl_members.csv)

Ensure your CSV is structured as follows:

GroupName,MemberEmail
Sales Team 0101,user1@7xh7fj.onmicrosoft.com
Sales Team 0101,user2@7xh7fj.onmicrosoft.com
Marketing Team 0101,user3@7xh7fj.onmicrosoft.com
Support Team 0101,user4@7xh7fj.onmicrosoft.com

Each row associates a member with a group. You can include multiple entries for the same group if adding more than one member.


How the Script Works

  1. Connects to Exchange Online
  2. The script starts by establishing a session with Exchange Online using Connect-ExchangeOnline.

  3. Imports a CSV File
  4. Using Import-Csv, the script reads all group-member associations from the CSV file.

  5. Loops Through Each Entry
  6. A foreach loop reads each line and uses Add-DistributionGroupMember to add the user to the respective group.

  7. Includes Error Handling
  8. If a member addition fails, the script catches the error and logs a warning — ensuring the rest of the script continues running smoothly.

🔄 Graph PowerShell cannot be used for managing traditional Distribution Lists. Tasks like member additions require Exchange PowerShell.


Further Enhancements

Here are a few ideas to take this script to the next level:

  • Log Results to a File
  • Track which additions succeeded or failed:

    "Added $($entry.MemberEmail) to $($entry.GroupName)" | Out-File "DL-Member-Log.txt" -Append
  • Validate User Existence
  • Use Get-User -Identity $entry.MemberEmail before adding to avoid invalid addresses.

  • Email Summary Report
  • Send a success/failure summary to an admin using Send-MailMessage or Send-MgUserMail.

  • Add Role-Based Members
  • Extend the script to add different roles (managers, assistants) based on department or tags.


Possible Errors & Solutions

Error Cause Solution
Access is denied Missing Exchange permissions Ensure the user has Exchange admin or recipient management role
Cannot find recipient Invalid email in CSV Verify email addresses are accurate and exist in the tenant
Object not found Group name doesn't match Use the Display Name of the DL, not its alias or email
Already a member Member already in group This is safe to ignore; the cmdlet will skip without issue

Conclusion

While Microsoft Graph PowerShell is the go-to for managing modern Microsoft 365 Groups, Exchange Online PowerShell is still required for managing classic Distribution Lists, especially for bulk member additions.

This script provides a quick, automated way to assign users to their respective DLs using a familiar CSV format — saving time and ensuring consistency.

🛠️ Simple, scalable, and essential for IT admins who manage user communication groups at scale.


Graph PowerShell Explorer Widget

20 Graph PowerShell cmdlets with easily accessible "working" examples.


Permission Required

Example:


                


                


                

© m365corner.com. All Rights Reserved. Design by HTML Codex