Create Office 365 Group using Powershell

Office 365 Groups provide a platform for collaboration that enables teams to come together and establish a single team identity and a single set of permissions across different Office 365 apps including Outlook, OneDrive, OneNote, Skype for Business, Power BI and Dynamics CRM. In this article, I am going write powershell commands to create Office 365 Groups, add members and owners to an Office 365 Group.

Before proceed, first connect Exchange Online Powershell session by using the following commands.

$365Logon = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $365Logon -Authentication Basic -AllowRedirection
Import-PSSession $Session

We can use the PowerShell cmdlet New-UnifiedGroup to create a new Office 365 group. This cmdlet includes the following key parameters:

DisplayName – display name of the new group
Alias – Email alias of the group. If you omit the parameter, it will generate an alias by using display name.
AccessType – Privacy type of the group (Public or Private)
AutoSubscribeNewMembers – Add this parameter to auto subscribe new members to the group

Use the below command to create a new group with minimal parameters.

New-UnifiedGroup –DisplayName "Test O365 Group 1"

Create the group with key parameters.

New-UnifiedGroup –DisplayName "Test O365 Group 2" -Alias "TestO365Group2" -AccessType Public

Once we created the group, we can use Get-UnifiedGroup cmdlet to list all the available groups.

Add Members and Owners to Office 365 Group

We can use Add-UnifiedGroupLinks cmdlet to add members and owners to the group. This cmdlet includes the following key parameters:

Identity – Alias, Display name, or Email address of the group
Links – Alias, Display name, or Email address of the user being added
LinkType – Members, Owners, or Subscribers

Add an user as owner: To add an user as owner to the group, first we need the user as a member to the specified group.

Add-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Members –Links Morgan
Add-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Owners –Links Morgan

Add member:

Add-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Members  –Links AlexD

Add subscriber:

A subscriber who receives updates by email can be added by changing the LinkType to “Subscribers”

Add-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Subscribers  –Links AlexD

The parameter Links accept multiple values, use the following syntax: value1,value2…. If the values contain spaces or otherwise require quotation marks, use the following syntax: “value1″,”value2”,….

Add members to multiple office 365 groups

$Groups = "group 01","group 02","group 03"
$Groups | ForEach-Object {
Add-UnifiedGroupLinks –Identity $_ –LinkType Members  –Links "Morgan" }

Import office 365 group members from a CSV File

You can use the below powershell commands to add members to an office 365 group by importing users from csv file. Consider the csv file members.csv that includes the column member which holds the member identity in each row of the csv file.

Import-CSV "C:\members.csv" | ForEach-Object {
Add-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Members  –Links $_.member
}

Find members and owners of a group

Once we added the members and owners, we can use Get-UnifiedGroupLinks cmdlet to get members or owners of a specific group. The below command lists all members of the given group.

Get-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Members

List owners of a group.

Get-UnifiedGroupLinks –Identity "TestO365Group2" –LinkType Owners

Advertisement

2 thoughts on “Create Office 365 Group using Powershell”

Leave a Comment