add bulk of members in CSV file to DL via PowerShell

IT 140 Reputation points
2023-12-04T15:45:00.0233333+00:00

I am looking for a power shell command to add bulk of users into DL (Exchange Online). I have a CSV file contain the users and email address.

I appreciate your kind help

Exchange Online
Exchange Online
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Answer accepted by question author
  1. Rich Matheisen 48,026 Reputation points
    2023-12-09T19:32:21.8566667+00:00

    Now that you have (or will have) a usable CSV file (https://en.wikipedia.org/wiki/Comma-separated_values):

    Import-Csv tt.csv |
        ForEach-Object{
        	Add-DistributionGroupMember -identity "DL Identity Goes Here" -member $_.Email
        }
    
    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Kai Yao 37,776 Reputation points Moderator
    2023-12-05T01:31:05.7+00:00

    Hi @IT,

    If the format of csv file is like:

    01

    You can run the following script to bulk add users:

    (replace $member.Email with the corresponding column header in your csv file, for example if the header is "EmailAddress", you need to use $member.EmailAddress)

    $members = import-csv users.csv
    foreach($member in $members)
    {
    	Add-DistributionGroupMember -identity "DL email address" -member $member.Email
    }
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Rich Matheisen 48,026 Reputation points
    2023-12-08T19:49:46.2566667+00:00

    If the screenshot of your "csv", viewed in Excel, looks like below, then expand the width of column "A" and I think you'll see that all of your data are in only one column.

    User's image

    If you exported that to a CSV format you'd have a text file that looks like this:

    "Name,Email"
    """ParentUK1"",""******@uk.co.uk"""
    

    If you were to import that using Import-CSV you'd get PSCustombjects with only one property: Name,Email and, as a value for that property you'd see "ParentUK1","******@uk.co.uk".

    As a result, there's no "Email" property, nor a "Name" property.

    If all of that is not what you're dealing with, then we need to see the contents of (say) the first three lines of the file "tt.csv". You can use Get-Contents tt.csv | select-object -first 3 to do that.


  3. IT 140 Reputation points
    2023-12-15T20:09:21.21+00:00

    Kindly find the result

    User's image


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.