Skip to content

How to add members to Distribution Group with PowerShell

You can add multiple users to an existing distribution list or mail-enabled security group in Microsoft admin portals. But with PowerShell, it’s much faster, and you use a CSV file to add the members to multiple distribution list groups. In this article, you will learn how to add members to a distribution group with PowerShell.

Connect to Exchange Online PowerShell

To be able to run PowerShell commands, you must Connect to Exchange Online PowerShell. Open Windows PowerShell as administrator, run the below cmdlet, and sign in with your admin credentials.

Connect-ExchangeOnline

Add-DistributionGroupMember Error: You don’t have sufficient permission

Each distribution group has at least one manager (owner). It means only the distribution group manager is allowed to perform these management tasks. So when the Exchange Online administrator tries to update the properties of the distribution group with the Add-DistributionGroupMember cmdlet, and it’s not the manager of this distribution group, the following error message appears.

Error: You don’t have sufficient permissions. This operation can only be performed by a manager of the group.

Notice that even a user with global administrator credentials can’t add a member or make a change to a distribution group. The fact that you are not the distribution group manager could stop you from completing the required management task.

The PowerShell cmdlets you need to use for managing a distribution group include a parameter named -BypassSecurityGroupManagerCheck. So whenever you try to perform a management task, and the permission error appears, you can add the -BypassSecurityGroupManagerCheck parameter to the original PowerShell command.

See the PowerShell command syntax example.

Add-DistributionGroupMember "Distribution Group" -Member "Identity" -BypassSecurityGroupManagerCheck

Run the PowerShell command example.

Add-DistributionGroupMember "SalesUK@m365info.com" -Member "Amanda.Morgan@m365info.com" -BypassSecurityGroupManagerCheck

In our example, anyone can add a member to the distribution group (Sales UK).

Adding users to Distribution Group

You can always add a user as a new member to an existing distribution group. We will show you different situations:

  1. Add a single member to an existing distribution group
  2. Add bulk users to a single existing distribution group
  3. Add multiple users to a single existing distribution group
  4. Add bulk users to all existing distribution group

For this, we need to use the Add-DistributionGroupMember PowerShell cmdlet.

Add member to Distribution Group

It’s always possible to add a specific member to an existing distribution group.

See the PowerShell command syntax.

Add-DistributionGroupMember "Distribution Group" -Member "Identity" -BypassSecurityGroupManagerCheck

Run the below PowerShell command example.

Add-DistributionGroupMember -Identity "SalesUK@m365info.com" -Member "Amanda.Hansen@m365info.com" -BypassSecurityGroupManagerCheck

Add users from CSV to specific Distribution Group

We want to add multiple members to an existing distribution group by importing a list of all users from a CSV file with PowerShell.

  1. Run the PowerShell command to export a list of all active user mailboxes in your organization
Get-Mailbox -ResultSize Unlimited | Select DisplayName, Alias, PrimarySmtpAddress | Export-Csv "C:\temp\Distribution Group Members.csv" -NoTypeInformation -Encoding UTF8
  1. Go to the C:\temp folder
  2. Open the CSV file to see the list of all user mailboxes
Add members to existing Distribution Group with PowerShell export CSV
  1. Each user has multiple identities, such as Display name, Alias, and Primary SMTP address
  2. You can edit the list and remove the users you don’t want to add as a member of the distribution group (optional)
Add members to existing Distribution Group with PowerShell export CSV file

In our example, we want to add this list of users to a specific distribution group named Sales France.

  1. Type the specific distribution group identity in line number 3 in the script below
  2. Run the below PowerShell script
$Userslist = Import-Csv "C:\temp\Distribution Group Members.csv"
ForEach ($User in $Userslist) {
    Add-DistributionGroupMember -Identity "SalesFrance@m365info.com" -Member $User.PrimarySmtpAddress -BypassSecurityGroupManagerCheck
}

Note: You will get a message in the output if the user is already a member of the group or if the user doesn’t exist.

Add-DistributionGroupMember: Ex93E602|Microsoft.Exchange.Management.Tasks.MemberAlreadyExistsException|The recipient
"David.Kent@m365info.com" is already a member of the group "Sales France".
Add-DistributionGroupMember: Ex94914C|Microsoft.Exchange.Configuration.Tasks.ManagementObjectNotFoundException|Couldn't
find object "Mary.James@m365info.com". Please make sure that it was spelled correctly or specify a different object.

Add all users from specific department to Distribution Group

You can add all the users from a specific department in your organization, like Sales, to an existing distribution group.

In our organization, we have multiple Sales departments, like Sales UK, Sales USA, and Sales France.

We want to get all the users from all the Sales departments and add them as members to the distribution list group AllSalesDepartments.

  • We need to find all the users from the Sales department by using the PowerShell string Sales*.
  • We use the variable $SalesUsers to store this information about the users’ list.
  • Then, we run a PowerShell loop process, which will use the information stored in the variable $SalesUsers and add each member stored in the $SalesUsers variable to the distribution group AllSalesDepartments.

Run the below PowerShell script.

$SalesUsers = Get-User | Where { $_.Department -like "Sales*" }
foreach ($User in $SalesUsers) {
    Add-DistributionGroupMember -Identity "AllSalesDepartments@m365info.com" -Member $User.Name -BypassSecurityGroupManagerCheck
}

You managed to add members to the existing distribution group with PowerShell.

Bulk add members to multiple Distribution Groups from CSV

You can add existing users as members to multiple distribution list and mail-enabled security groups from a CSV file. You need to create a CSV consisting of two columns. A column including a list of distribution groups and a column with existing users you wish to add as a member.

Create a CSV file with two columns:

  1. Open Notepad or Microsoft Excel
  2. Type GroupName at the top of the first column
  3. List the existing distribution group primary SMTP address
  4. Type Member at the top of the second column
  5. List the UserPrincipalName of the members

Note: The column name GroupName must not contain any space, and the distribution groups must exist.

See the below CSV file example.

Add Distribution Group members with PowerShell CSV
  1. Create the folder temp if you don’t have it already in the (C:) drive
  2. Name the file DL Group Members.csv
  3. Save as type CSV (Comma delimited (*.csv)
  4. Click Save
  5. Run the below PowerShell script
# Specify the path to your CSV file
$csvPath = "C:\temp\DL Group Members.csv"

# Import the CSV file
$csvData = Import-Csv -Path $csvPath

# Loop through each row in the CSV file and update the distribution group
foreach ($row in $csvData) {
    $member = $row.Member
    $groupName = $row.GroupName

    # Check if the user specified in Member exists
    $userExists = @()
    $userExists += Get-User -Identity $member -ErrorAction SilentlyContinue
    $userExists += Get-Contact -Identity $member -ErrorAction SilentlyContinue

    # Check if the distribution group specified in GroupName exists
    $groupExists = Get-DistributionGroup -Identity $groupName -ErrorAction SilentlyContinue

    if ($userExists -and $groupExists) {
        # Both user and group exist, so proceed with updating the distribution group
        try {
            # Get the user's ID
            $userID = $userExists.Identity

            # Check if the user is already a member of the group
            $isMember = Get-DistributionGroupMember -Identity $groupName | Where-Object { $_.Identity -contains $userID }

            if (-not $isMember) {
                # User is not a member, so add them
                Add-DistributionGroupMember -Identity $groupName -Member $member -BypassSecurityGroupManagerCheck -ErrorAction Stop
                Write-Host "Added user $member as member to $groupName." -ForegroundColor Green
            }
            else {
                Write-Host "User $member is already a member of $groupName. No action needed." -ForegroundColor Cyan
            }
        }
        catch {
            Write-Host "Failed to update member for $groupName. Error: $($_.Exception.Message)" -ForegroundColor Red
        }
    }
    elseif (-not $groupExists) {
        # Group doesn't exist, display a message
        Write-Host "Distribution group $groupName specified in GroupName column doesn't exist. Skipping." -ForegroundColor Yellow
    }
    elseif (-not $userExists) {
        # User doesn't exist, display a message
        Write-Host "User $member specified in member column doesn't exist. Skipping." -ForegroundColor Yellow
    }
}

The PowerShell output result shows:

  • When you add a user as a member of the distribution group
  • If the distribution group doesn’t exist
  • If the user is already a member of the distribution group
  • The user doesn’t exist in Microsoft 365
Added user Adam.Mackay@m365info.com as member to SalesFrance@m365info.com.
User Amanda.Morgan@m365info.com is already a member of SalesFrance@m365info.com. No action needed.
Distribution group SalesUK@m365info.com specified in GroupName column doesn't exist. Skipping.
User Jill.Bates@m365info.com specified in member column doesn't exist. Skipping.
Added user George.Wilson@m365info.com as member to SalesGermany@m365info.com.
Added user Brenda.Smith@m365info.com as member to SalesGermany@m365info.com.
User Unknown@m365info.com specified in member column doesn't exist. Skipping.

Add user to multiple Distribution Groups

We will show you how to add a specific user to multiple distribution groups in different ways.

Add user to multiple Distribution Groups

You can add a single user as a member to multiple distribution lists and mail-enabled security groups. Use the below script and type which member you want to assign to the different distribution groups.

The script consists of two parts:

  • Specify the distribution groups primary SMTP addresses in line number 1
  • Specify the UserPrincipalName of the member you want to add in line number 3

In our example, we want the user Brenda.Smith@m365info.com to be a member of two distribution groups (Sales UK & Sales USA).

Run the below PowerShell example.

$DistributionGroupsList = "SalesUK@m365info.com", "SalesUSA@m365info.com"
ForEach ($DistributionGroup in $DistributionGroupsList) {
    Add-DistributionGroupMember -Identity $DistributionGroup -Member "Brenda.Smith@m365info.com" -BypassSecurityGroupManagerCheck
}

Note: You will get a message in the output if the user is already a member of the group or if the user doesn’t exist.

Add user to bulk all Distribution Groups

In this scenario, we want to add a specific user to all the existing distribution lists and mail-enabled security groups.

  • We will use a variable named $AllDistributionGroups that will get the distribution list and mail-enabled security groups in the entire organization.
  • Then, we use the ForEach PowerShell statement to execute a loop process on the list of existing distribution groups.
  • Specify the UserPrincipalName of the member you want to add on line number 3 in the script below.

Run the below PowerShell script example.

$AllDistributionGroups = Get-Distributiongroup -ResultSize Unlimited
ForEach ($DistributionGroup in $AllDistributionGroups) {
    Add-DistributionGroupMember -Identity $DistributionGroup -Member "David.Kent@m365info.com" -BypassSecurityGroupManagerCheck
}

Note: You will get a message in the output if the user is already a member of the group or if the user doesn’t exist.

Add user to multiple Distribution Groups from CSV file

Another way to add a specific user to multiple distribution lists and mail-enabled security groups from a CSV file. You need to create a CSV that includes a list of distribution groups to which you wish to add this user as a member.

Create a CSV file with two columns:

  1. Open Notepad or Microsoft Excel
  2. Type GroupName at the top of the first column
  3. List the existing distribution groups’ primary SMTP address
  4. Enter Type at the top of the second column
  5. Type Distribution or Security

Note: The column GroupName must not contain any space, and the distribution groups must exist.

Add members to Distribution Group with PowerShell from CSV
  1. Create the folder temp if you don’t have it already in the (C:) drive
  2. Name the file DL Group Type.csv
  3. Save as type CSV (Comma delimited (*.csv)
  4. Click Save
Add members to existing Distribution Group with PowerShell save CSV DL Group Type
  1. Check CSV file with Import-Csv cmdlet

To ensure that PowerShell can read the file, run the Import-Csv cmdlet.

Import-Csv "C:\temp\DL Group Type.csv"
  1. Specify the UserPrinicipalName of the member in line number 3
  2. Run the below PowerShell script
$DistributionGroupsList = Import-Csv "C:\temp\DL Group Type.csv"
ForEach ($DistributionGroup in $DistributionGroupsList) {
    Add-DistributionGroupMember -Identity $DistributionGroup.GroupName -Member "Amanda.Hansen@m365info.com" -BypassSecurityGroupManagerCheck
}

Note: You will get a message in the output if the user is already a member of the group or if the user doesn’t exist.

Add user to Distribution Groups created in the last 48 hours

You can add a specific user to all the newly created distribution groups in the last 48 hours.

In our example, we will add the user Brenda.Smith@m365info.com to the distribution groups created in the last 48 hours.

Run the below PowerShell example.

$AllNewDistributionGroups = Get-DistributionGroup -ResultSize Unlimited | Where-Object { $_.WhenCreated -ge (Get-Date).AddHours(-48) }
ForEach ($DistributionGroup in $AllNewDistributionGroups) {
    Add-DistributionGroupMember -Identity $DistributionGroup.DistinguishedName –Member "Brenda.Smith@m365info.com" -BypassSecurityGroupManagerCheck
}

Note: You will get a message in the output if the user is already a member of the group or if the user doesn’t exist.

Add user to Distribution Group if not member

You want to verify if a specific user is a member of an existing distribution group. In our example, we want to check if Brenda Smith is a member of the distribution group Sales UK.

  • The user we want to check is Brenda Smith
  • The distribution group name is Sales UK

If the specific user (Brenda Smith) is not a member of the distribution group Sales UK, then we want to add the user as a member of the distribution group.

Run the below PowerShell example.

$User = Get-User -Identity "Brenda.Smith@m365info.com"
$Group = Get-DistributionGroup -Identity "SalesUK@m365info.com"
if ($Group.PrimarySmtpAddress -notcontains $User.Name)
{ Add-DistributionGroupMember -Identity $Group.PrimarySmtpAddress -Member $User.Name -BypassSecurityGroupManagerCheck }

It automatically adds the user as a member of the distribution group.

Read more: Unblock Microsoft 365 user sign-in »

Conclusion

You learned how to add distribution group members with PowerShell. It’s possible to add a single user or multiple users as a member to an existing distribution group. With Powershell, there are many ways to get the task done, and it saves time.

Did you enjoy this article? You may also like Reset MFA for Microsoft 365 user. Don’t forget to follow us and share this article.

o365info Team

o365info Team

This article was written by our team of experienced IT architects, consultants, and engineers.

This Post Has One Comment

  1. Hi,

    First of all, I would like to thank you and your team.
    Your all articles are very clear and help full.
    I have tried to find PowerShell example for dynamic distribution list using filter Department and Designation and Company but not found.
    It will be great help, If provide the script with example.

    With best regards,

Leave a Reply

Your email address will not be published. Required fields are marked *