Connect To PowerShell First

We have a couple of customers that want to maintain distribution groups of external contacts that can be used company wide.

The way to do this as an Exchange admin is to create a Mail Contact for an external user first, and then add that mail contact to a distribution group. This can be quite an involved process, and you may not want to have users traversing the Exchange Admin Center to complete this sort of task.

To make this easier, we’ve put together a power shell script that you can download here.

Assign the minimum permissions

Any Global administrator will be able to run this powershell script, though if you want to give a user the ability to execute the commands, you’ll need to assign them to the appropriate role groups. These are Recipient Management and Organization Management. Keep in mind, even though these are the minimum permissions required to run this Powershell script, they still enable the relevant user to do pretty much everything within Exchange. For a full list of the permissions granted, see these links:

To give a user the correct permissions, connect to Exchange Online via Powershell as a global administrator and run the following commands. Replace user@domain.com with the identity of the relevant user.

Add-RoleGroupMember "Recipient Management" -Member user@domain.com
Add-RoleGroupMember "Organization Management" -Member user@domain.com

Running the PowerShell Script

Once the user has been granted access they can run the powershell script under their own credentials.

  1. Download the script here. 
  2. Rename it with a file extension of .ps1 eg. DistributionGroups.ps1
    Rename Distribution Groups To DistributionGroups.ps1
    DistributionGroups.Ps1
  3. Run the script by right clicking the file and choosing Run in PowershellRight Click to Run With Powershell
  4. Press 1, then Enter to connect to Exchange Online. Press Enter again once the commandlets have downloaded.Connect To PowerShell First
  5. Follow the menu items within the PowerShell script to perform the following actions:
  • Add Mail Contacts to distribution groups
  • Get a list of distribution groups
  • Create a distribution group
  • Get a list of distribution group members
  • Remove a contact from all distribution groups
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

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