Monday, 30 May 2016

Create Distribution Group in Office 365 using Powershell

In this article, I am going write powershell commands to create Distribution Groups and add members to a Distribution Group in Office 365 environment. We can use the Exchange Online powershell cmdlet New-DistributionGroup to create a new distribution list.

Before proceed, first connect Exchange Online Powershell session by using the following commands.
$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session
After connecting Exchange Online service, run the following command to create a Distribution Group.

New-DistributionGroup -Name <DG name> -DisplayName <DG display name> -Alias <Alias>
New-DistributionGroup -Name "DG-Sales" -DisplayName "DG-Sales" -Alias "DG-Sales"

Add members to Distribution List:

We can use the cmdlet Add-DistributionGroupMember to add member to distribution group in office 365.
Add-DistributionGroupMember "DG-Sales" -Member Morgan

Add members to multiple Distribution groups:

$Groups = "DG 01","DG 02","DG 03"
$Groups | ForEach-Object {
Add-DistributionGroupMember -Identity $_ –Member "Morgan" }

Import Distribution Group members from a CSV File:

You can use the below powershell commands to add members to Distribution List by importing members from csv file. Consider the csv file members.csv that includes the column member which holder the member identity in each row of the csv file.
Import-CSV "C:\members.csv" | ForEach-Object {
Add-DistributionGroupMember -Identity "DG-Sales" -Member $_.member


No comments:

Post a Comment