Working with Office 365 Groups using PowerShell

Posted Tuesday, May 12, 2015 2:16 PM by CoreyRoth

New features are coming fast to Office 365 Groups.  As administrators we have been looking for ways to simplify the management of groups.  This includes functions like adding groups, deleting groups, and adding members to groups.  At Ignite last week in session BRK3114 they showed us some of the new PowerShell cmdlets available to make this happen.  There isn’t any documentation on this stuff at all yet, so I wanted to show you some of the stuff that was showed at the conference.

Establishing a connection to Exchange Online

Groups are ultimately powered by Exchange (and then SharePoint).  As a result, we make use of the Exchange Online cmdlets.  If you have never used these cmdlets before, we start by creating a session.  Start by opening a PowerShell window of your choice.  We’ll be following the steps provided by TechNet.

First, get your credentials in PowerShell and store them in a variable using Get-Credential.  A window will pop up prompting you for your credentials.   Use your Office 365 Global Administrator account.

$userCredential = Get-Credential


Now, we need to create a session with New-PSSession and pull down the Exchange Online cmdlets.  Executing this command will yield no output.

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $UserCredential -Authentication Basic -AllowRedirection


Finally, use Import-PSSession to make the connection.  This takes a few moments as it shows you all of the cmdlets it has loaded.

Import-PSSession $session


If you examine the output closely you’ll see some cmdlets for groups in there.  Now we are ready to being working with groups on our tenant.

Getting a list of all groups

Let’s start by seeing what groups are present with Get-UnifiedGroup.  Type the following in PowerShell.



That’s odd.  It returned only one group and I have more than that on my tenant.


This is because if you have existing groups, they are likely in a state of transition to a new type of object in Azure Active Directory that can be synchronized back to your on-premises Active Directory Domain Services.  This deployment is only temporary though and it may already be working on your tenant.  I created a new one through the user interface today and it showed up.  The one I created months ago did not.

Creating a new group

To create a new group with PowerShell, we use the New-UnifiedGroup cmdlet.   Here are the key parameters:

  • DisplayName – display name of the group
  • Alias – alias of the group if you want to override it.  If you omit the parameter, it will generate an alias for you.
  • AccessType – Public or Private
  • AutoSubscribeNewMembers – Add this parameter to auto subscribe new members to the group

The Members parameter which takes an array of Recipient Ids to add users to the group.  There is also a large number of other parameters that allow you to customize things even further.  I am pretty sure some of these parameters aren’t even configurable in the user interface yet.

To create a group with minimal parameters, just use the DisplayName parameter:

New-UnifiedGroup –DisplayName "PowerShell Group 1"


Unfortunately, since the cmdlets are still under development, this one doesn’t work right now.  However, it might work by the time you try it.

Adding users to a group

The cmdlet to add users to a group in PowerShell, Add-UnifiedGroupLinks, actually does work right now.  Here are some of the key parameters:

  • Identity – Alias of the group
  • Links – login or alias of the user being added
  • LinkType – Members, Owners, or Subscribers

To add a new user to the members group:

Add-UnifiedGroupLinks groupalias –Links –LinkType Member


Successful execution will not yield any output.

To add a new user to the owners group, first add them as a member and then add them as an owner.

Add-UnifiedGroupLinks groupalias –Links –LinkType Member

Add-UnifiedGroupLinks groupalias –Links –LinkType Owner


You can verify that your users are in the group through the Groups user interface.  Note that the user “Joy” is listed as an owner.


We can also verify the users are in the group via PowerShell.

Getting the members of a group

We can use PowerShell to view the members of an existing group with the Get-UnifiedGroupLinks cmdlet.  The key parameters for this cmdlet are:

  • Identity – the alias of the group
  • LinkType – Members, Owners, or Subscribers.  Required.

To see the members of a group with PowerShell, issue the following command:

Get-UnifiedGroupLinks –Identity groupalias –LinkType Members


Removing a user from a group

You can remove a member from a group using Remove-UnifiedGroupLinks.  Here are the parameters:

  • Identity – alias of the group
  • Links – login or alias of the user to be removed
  • LinkType – Member, Owner, or Subscriber.  Required.

To remove a user as a member from the group, use the following command:

Remove-UnifiedGroupLinks groupalias –Links –LinkType Member


To remove an owner from the group, you will first have to remove he or she from the LinkType Owner.

Remove-UnifiedGroupLinks groupalias –Links –LinkType Owner

Remove-UnifiedGroupLinks groupalias –Links –LinkType Member

Removing a group

As expected, the cmdlet to remove a group doesn’t function right now either.  We can still look at the syntax though.

Remove-UnifiedGroup groupalias

Getting help with the groups cmdlet

You can type help unifiedgroup to load the help modules for Groups.  When you do, you’ll again get a bunch of verbose information followed by the listing of cmdlets.  Unfortunately, they don’t provide any real documentation yet, but you can see a listing of parameters using get-help.



This is truly a case where we are getting early access to PowerShell functionality.  While not all of the functionality is ready yet, it’s great to see that we can get started.  Just being able to easily add members to a group using a PowerShell script already is a huge win!  Remember that these cmdlets are highly subject to change right now before you invest a lot of time building scripts around them.  I’ll update this post when the cmdlets are finalized.

If you want to learn more about working with Groups, be sure and watch Ignite Session BRK3114 where they demonstrate some of these cmdlets in action.


# Office 365: Trabajo con Grupos por medio de PowerShell (I)!

Wednesday, May 27, 2015 2:02 AM by Blog de Juan Carlos González en Geeks.MS

Una de las últimas novedades incorporadas por Microsoft a los Grupos de Office 365 es la disponibilidad

# re: Working with Office 365 Groups using PowerShell

Monday, January 16, 2017 1:13 PM by M.Shehata

Thank you it really helped :)

# re: Working with Office 365 Groups using PowerShell

Wednesday, January 18, 2017 11:25 AM by John

Hello how do you add users to the Office 365 group in bulk off a csv or txt?

Leave a Comment