Manage Distribution Groups by using PowerShell | Office 365 5/5 (2) 11 min read

The current article, is that first article on the five-article series, which is dedicated to the subject of managing Distribution Group in Office 365 and Exchange Online based environment using PowerShell.

The purpose of this article is to provide a “slim version” of PowerShell command index, that we need to use for common Distribution Group management tasks.

For each section in the article such as – Creating New Distribution Group and managing existing Distribution Groups, adding members to existing Distribution Group I have dedicated separated article.

If the “short version” of the PowerShell command is not sufficient for you, and you need more information or more examples, you are invited to read the specific article if the Distribution Group malmanagement via PowerShell article series.

1. Creating New Distribution Group

In case that you want to get more detailed information about – Distribution Group management using PowerShell, and the subject of “Creating Distribution Groups”, you can read the following article – Manage Distribution Group using PowerShell in Office 365 | Creating New Distribution Group and managing existing Distribution Groups | Part 2#5

Create NEW Distribution Group (use default settings).

PowerShell command syntax

PowerShell command Example

Create NEW Distribution Group + set additional Distribution Group settings.

PowerShell command syntax

PowerShell command Example

Creating Distribution Groups by importing information from a CSV File

PowerShell command syntax

PowerShell command Example

Creating Distribution Groups by importing information from a CSV File

Note – You can download the CSV files that we use in the article for a demonstration purpose.

2. Manage existing Distribution Group settings

In case that you want to get more detailed information about – Distribution Group management using PowerShell, and the subject of “Managing Distribution Groups”, you can read the following article – Manage Distribution Group using PowerShell in Office 365 | Creating New Distribution Group and managing existing Distribution Groups | Part 2#5

Enable or disable Distribution Group to get E-mail from external senders

To enable the external recipient to send E-mail to Exchange Online Distribution Group, we set the value of the parameter “RequireSenderAuthenticationEnabled” to $False.

PowerShell command syntax

PowerShell command Example

Enable an external recipient to send E-mail to all Distribution Groups (bulk mode).

PowerShell command Example

Adding or replacing Distribution Group owner

Replace existing Distribution Group owner

PowerShell command syntax

PowerShell command Example

Adding additional owner\s to Distribution Group

PowerShell command syntax

PowerShell command Example

Manage Distribution Group E-mail address

Set Distribution Group Primary E-mail address

PowerShell command syntax

PowerShell command Example

Set Distribution Group Primary E-mail address by importing information from CSV file

In our example, the CSV file name is Distribution-Groups-information.csv

Set Distribution Group Primary E-mail address by importing information from a CSV file

PowerShell command Example

Note – You can download the CSV files that we use in the article for a demonstration purpose.

Add additional E-mail address to existing Distribution Group E-mail address

PowerShell command Example

Replace (remove) existing Distribution Group Alias E-mail

PowerShell command Example

Remove existing Distribution Group Alias E-mail addresses

PowerShell command syntax

PowerShell command Example

Hide Distribution Group from GAL (Global address list).

Hide Distribution Group from GAL (Global address list)

PowerShell command syntax

PowerShell command Example

Set an existing Distribution Group to accept E-mail only from a specific sender

Set an existing Distribution Group to accept E-mail only from a specific sender

PowerShell command syntax

PowerShell command Example

Define a Distribution Group Moderator

Define a Distribution Group Moderator

PowerShell command syntax

PowerShell command Example

Send out of office reply for a Distribution Group

Send out of office reply for a Distribution Group

PowerShell command syntax

PowerShell command Example

Assign “Send As” Permissions to Distribution Group

Assign “Send As” Permissions to Distribution Group

PowerShell command syntax

PowerShell command Example

3. Adding users to a Distribution Group

In case that you want to get more detailed information about – Distribution Group management using PowerShell, and the subject of “Adding members to existing Distribution Group”, you can read the following article – Manage Distribution Group using PowerShell in Office 365 | Adding members to existing Distribution Group | Part 3#5

Add a user (recipient) to a Distribution Group

Add a user (recipient) to a Distribution Group

PowerShell command syntax

PowerShell command Example

Add a list of users to a specific Distribution Group

Import Distribution Group members from a CSV File

PowerShell command Example

Add user (recipient) to multiple distribution groups

PowerShell command syntax

Import Distribution Group members from a CSV File

PowerShell command Example

Using a CSV file as a source of information for Distribution Group members -03

Add to Distribution Group all the users whom their department is Sales*

PowerShell command Example

Note – You can download the CSV files that we use in the article for a demonstration purpose.

Add user to distribution groups that were created in the last 48 hours

PowerShell command Example

4. View information about Distribution Groups

In case that you want to get more detailed information about – Distribution Group management using PowerShell, and the subject of “view and export information about Distribution Groups”, you can read the following article – Manage Distribution Group using PowerShell in Office 365 | view and export information about Distribution Group | Part 4#5

Display all Distribution Groups list + details

PowerShell command Example

Display Distribution Group Members

Display Distribution Group Members

PowerShell command syntax

PowerShell command Example

Count the number of Distribution Group members

PowerShell command Example

Display list of Distribution Groups with specific Email Domain name suffix

Display list of Distribution Groups with specific Email Domain

PowerShell command syntax

In our specific example, we look for Distribution Group that their E-mail address includes the domain name – o365info.com

PowerShell command Example

Display information about Distribution Group that was updated before or after specific date range.

Get a list of Distribution Groups, that was created in the last 2 weeks

PowerShell command Example

Display all Distribution Groups which their owner (managed by) is user X

PowerShell command Example

Display all Distribution Groups which have a moderator

PowerShell command Example

Display all Distribution Groups that are synchronized from On-Premise Active Directory

PowerShell command Example

Display Distribution Group information about delivery management

Display Distribution Groups which their delivery management allows external recipients
to send E-mail

Display Distribution Groups that accept E-mail from external recipients

PowerShell command Example

Display Distribution Groups which their delivery management doesn’t allow external recipients to send E-mail

Display Distribution Groups that doesn’t accept E-mail from external recipients

PowerShell command Example

Get information about Distribution Group membership of a specific user.

PowerShell command Example

5. Removing members from Distribution Group

In case that you want to get more detailed information about – Distribution Group management using PowerShell, and the subject of “Delete Distribution Group and members, Convert Distribution Group type and more”, you can read the following article  – Manage Distribution Group using PowerShell in Office 365 | Delete Distribution Group and members | Convert Distribution Group | Part 5#5

Delete (Remove) a Distribution Group

Delete (Remove) a Distribution Group

To delete an existing Distribution Group, we use the following PowerShell command:

PowerShell command syntax

PowerShell command Example

Remove a member from a Distribution Group

PowerShell command syntax

PowerShell command Example

Remove user from all the Distribution Groups which he is a member in

PowerShell command Example

Remove all members from a Distribution Group

PowerShell command Example

Additional Distribution Group malmanagement tasks | tips and tricks

How to convert Distribution Group into a security group

Copy members from Distribution Group to a security group

PowerShell command Example

Assign “Full Access” permissions to Distribution Group + use AutoMapping option

Extract Distribution Group member’s, and assign Full access permissions for each group member

PowerShell command Example

Manage Distribution Group using PowerShell in Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article

Print Friendly

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

24 Responses to “Manage Distribution Groups by using PowerShell | Office 365”

  1. I have a distribution group that I created but did not set it as a security group. Now I need to set it as a security group. What is the powershell command to change this distribution group and add the option of being a security group?
    I have not found the line item needed to add this option.
    Set-DistributionGroup -Name “HDGroup”
    But this is as far as I have gotton and not sure what the syntax is for changing the distribution group to include the security switch which is only available when you create the distribution list in the gui.

  2. As far as I know, it is not possible to change a distributiongroup from one type to another. You may need to redo the process. At least in the GUI it has to be done that way.

  3. This script works for Office 365 and removes the single user from all Distribution Groups. It does go through all groups and fails on the ones where the user is not a member, but it’s quick and dirty.

    $email= read-host -prompt “Email Address”
    $DGs= Get-DistributionGroup

    foreach( $dg in $DGs){
    Remove-DistributionGroupMember $dg.name -Member $email -confirm:$false

    }

  4. Looking for something that can list distrobution groups a user is a member of…

    Kinda like this:
    $User = read-host -Prompt “Email Address”

    $user_dn = (Get-MsolUser -userprincipalname $user)

    “User ” + $User + ” is a member of the following groups:”

    foreach ($group in Get-Msolgroup -MaxResults 10000){ if ((Get-MsolGroupMember $group.identity | select -expand distinguishedname) -contains $user_dn){$group.name} }

    but cannot make it work

  5. Hello,

    Need some ideas to automate adding or removing members in outlook with Shell scripting. Can i get the script please.

    Thanks in advance.

  6. Hello,

    Need some ideas to automate adding or removing members in distribution group in outlook. Help me with the script.

    Thanks

  7. Bill

    Very Good, thanks, do you know how to use the -and statement.

    EG:
    get-distributiongroup |where {$_.OrganizationalUnit -like “*namehere*” -and $_.OrganizationalUnit -like “*othernamehere*”}

    as it does not work. I need to identify groups from certain org unit names

  8. Is there a power shell command that will hide or deny the sending to all Distribution Groups from 1 Distribution group?
    In other words, I have 1 Distribution group, that I do not want to be able to send to any other Distribution groups, nor do I want them to see Distribution Groups within the GAL.

    Thanks

  9. Please help with this command. We want all users that have titles of Manager under the Province of ON and the City of (Toronto and Ottawa) will receive the Emails when we send emails to Dynamic DL HomeManagers. PLease see command below.

    Command:

    New-DynamicDistributionGroup -Name “HomeManagers” -OrganizationalUnit “domain.ca/Groups”-RecipientFilter {(RecipientType -eq ‘UserMailbox’) -and (Title -eq ‘Manager*’) -and (StateOrProvince -eq ‘ON’) -and (City -eq ‘Toronto’) -or (City -eq ‘Ottawa’)}

    The command works but only Toronto users get the Emails but not the Ottawa users. Please advise.

  10. May the Shell be ever in your favor Reply

    Is there a script to get a list of all Exchange Distribution groups and whether or not they have the box checked for (Require that all senders are authenticated)? I am looking to audit this each year and looking to pull a quick list.

  11. Hi. I’m going to create several (about 40) new distribution lists, but I would like to add owner to it also. Do I have to run different cmdlets to do this, or can I run one? How can I create 40 DL in Powershell in the easiest way? I’m a beginner at Powershell, so I’d really appreciate some tips here

    Thanks.

  12. Wonderful site. Lots of useful info here. I’m sending it to several pals ans additionally sharing in delicious. And obviously, thanks to your sweat!

  13. I am looking for a script that can add distro lists to O365. But here is the caveat.

    I have a .csv file. It lists DisplayName, GroupAlias, and SMTP Email Address. So it lists the group name, the display name of the user, and email address of the user. Some of the email addresses are for outside contacts. I need a script that can import the groups, import the users, and create the external contacts as well. Any help is appreciated. I know in advance i am asking for the Holy Grail of scripts, but I have a LOT of groups and users to add.

  14. This blog was… how do I say it? Relevant!! Finally I’ve found something that helped me.
    Cheers!

  15. Do you know if a way to remove users from a distribution group that are NOT listed in the imported CSV?
    So that way I could have a single CSV file, and a powershell script that adds users from the CSV to the distribution group, but then removes any users who are NOT in the csv file, ensuring the csv & membership is always matched.

  16. DL created and added users to this DL. now i want to hide those users from DL.How can i hide, please suggest. Output should be as “if we double click DL it should not show the members in the DL.

Leave a Reply

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