Manage Distribution Groups using PowerShell

Manage Distribution Groups by using PowerShell

Mange Distribution Groups using PowerShell

The Exchange Online ECP (Exchange Control Panel) enables us to execute management task relating to Distribution Groups in an easy and convent way.
However, dissipate that fact, we can use PowerShell advantage for tasks that cannot be done by using the ECP interface such as: creating and
managing Dynamic distribution
group, a task such as: export information about group membership or create Bulk operations that influence more than one Distribution Group.

In this article, we review some of the basic management tasks related to Distribution Groups management.

PowerShell | Help & additional information

In case that you are a novice in the PowerShell environment, you can use the following link to get more information about the “first steps” such as: downloading the required PowerShell
software components, how to use the PowerShell console, running a PowerShell script, etc.

Read more
Link Table

PowerShell Naming Conventions & general information

If you want to get more information about the Naming Conventions that we use for this article and get some general tips about: how to work with the PowerShell, read the article: Help and additional information – o365info.com PowerShell articles

Create remote PowerShell session

Before we can use the required PowerShell commands, we need to download and install the Office 365 cmdlets + create remote PowerShell session to Office 365 or Exchange Online. If you need more information about how to create a remote PowerShell session read the following articles: Part 2: Connect to Office 365 by using Remote PowerShell and Part 3: Connect to Exchange Online by using Remote PowerShell

How to use a PowerShell script

Most of the PowerShell articles include a PowerShell script that simplifies the use of the PowerShell commands. If you want to get more information about: How to use a PowerShell script, read the article: Connect to Office 365 and Exchange Online using a script

PowerShell command and Script languish in more details

If you are new to the PowerShell world, you can read more information about PowerShell in Office 365 environment in the article: The Power of PowerShell


Expand All Headers Collapse All Headers



1 - Create and delete Distribution Groups

Create a Distribution Group

PowerShell command Syntax

PowerShell command Example

Create a Distribution Group + Details

PowerShell command Syntax

PowerShell command Example

Delete (Remove) a Distribution Group

PowerShell command Syntax

PowerShell command Example



2 - Manage Distribution Groups General Settings

Add user to a Distribution Group

PowerShell command Syntax

PowerShell command Example

Setting Distribution Groups to accept Senders outside of my organization

PowerShell command Syntax

PowerShell command Example

Adding Distribution Group owner

PowerShell command Syntax

PowerShell command Example

Set a specific user as owner of all Office 365 (Bulk Mode)

PowerShell command Syntax

PowerShell command Example

Add an Email Alias to Distribution group

PowerShell command Syntax

PowerShell command Example

Hide Distribution group from GAL

PowerShell command Syntax

PowerShell command Example

Create new Security Distribution Group

PowerShell command Syntax

PowerShell command Example

Adjustments & Customizations: Set Email Address for the Distribution Group

PowerShell command Example

Import Distribution Group members from a CSV File

PowerShell command Syntax

PowerShell command Example

Create Bulk Distribution Groups from a CSV File

PowerShell command Syntax

PowerShell command Example

Add recipient to multiple distribution groups

PowerShell command Syntax

PowerShell command Example

Enable external sender to send email to the distribution group (Bulk Mode)

PowerShell command Example

Prevent external sender to send email to the distribution group (Bulk Mode)

PowerShell command Example



3 - Assign Permissions to Distribution Groups

Assign “Send As” Permissions to Distribution Group

PowerShell command Syntax

PowerShell command Example

Assign “Full Access” permissions to Distribution Group + AutoMapping

PowerShell command Syntax

PowerShell command Example

Additional reading



4 - Manage Dynamic Distribution Groups

Create Dynamic Distribution Group for all Office 365 users

PowerShell command Syntax

PowerShell command Example

Create Dynamic Distribution Group for user from specific Office

PowerShell command Syntax

PowerShell command Example

Create Dynamic Distribution Group for all managers

PowerShell command Syntax

PowerShell command Example


Additional reading



5 - Display Information about Distribution Groups

Display Distribution Group Members

PowerShell command Syntax

PowerShell command Example

Display members of Dynamic Distribution Group

PowerShell command Syntax

PowerShell command Example

Display list of Distribution Groups

PowerShell command Syntax

Display list of Distribution Groups with specific Email Domain name suffix

PowerShell command Syntax

PowerShell command Example

Display information about Distribution Group that was updated before a specific date

PowerShell command Syntax

PowerShell command Example

Script Box

For your convenience, I have “Wrapped” all of the PowerShell commands that was reviewed, In a PowerShell Script named: Distribution list.ps1

Download Script

Print Friendly




Now it’s Your Turn!
We really want to know what you think about the article


Like this Article? Subscribe to Our Feed!

Eyal DoronManage Distribution Groups by using PowerShell

Comments 13

  1. Anonymous

    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. Anonymous

    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. Anonymous

    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. SprintGeek

    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. Ayesha

    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. Anonymous

    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

  7. Anonymous

    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

  8. Pingback: [O365] Dynamic Distribution Group

  9. yOn

    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.

Leave a Reply

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