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

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,695 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,604 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 47,501 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. Kael Yao-MSFT 37,676 Reputation points Microsoft Vendor
    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 47,501 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"",""test1@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","test1@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 Answers by the question author, which helps users to know the answer solved the author's problem.