Manage Office 365 Group Members and Owners with PowerShell

With PowerShell UnifiedGrouplinks cmdlet we can easily manage the Office 365 Group member- and ownerships. The UnifiedGroupLinks cmdlet is part of the Exchange Online PowerShell session. So before we can start adding Office 365 Group Members or change them to Owner we first need to connect to Exchange Online.


Connecting to Exchange Online

First we need to connect to Exchange Online, you can use this connector script or run the following code:

#Create credential object
$credObject = Get-Credential

#Import the Exchange Online ps session
$ExchOnlineSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credObject -Authentication Basic -AllowRedirection
Import-PSSession $ExchOnlineSession

Or with the connector script that makes everything a lot easier:

ConnectTo-ExchangeOnline.ps1

List Office 365 Group Member or Owners

So first let’s start with an overview of the current Office 365 Group Member or Owners:

Get-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members

This will return all members and owners of the Office 365 Group. A owners is also a member of the group. The see who are owners of the group we need to change the LinkType to Owner:

Get-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners

Adding Member and Owners to an Office 365 Group

You can’t add an Owner straight away to an Office 365 Group, first you will have to make it a member of the group and then you can change the role to owner. So we start with adding members to a Office 365 Group:

Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members  –Links [email protected],[email protected]
  • Identity : the Alias, Displayname or Email address of the Group
  • LinkType: can be Subscripbers, Members or Owners
  • Links: Alias, Displayname or Email addres of the users you want to add. (Multiple users can be added with a comma separation)

Adding a member to a Group takes a few seconds before it’s processed.

To make an user Owner we first add them as a member and then change the role to Owner:

Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links [email protected]
Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners –Links [email protected]

Removing Members or owners from an Office 365 Group

To remove an owner from a Office 365 Group we need first to change the role to member. So only member can really be removed from a Group:

Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners –Links [email protected] -Confirm:$false
Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links [email protected] -Confirm:$false

#To remove only a member
Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links [email protected] -Confirm:$false

 

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

4 thoughts on “Manage Office 365 Group Members and Owners with PowerShell”

    • $admin = “[email protected]
      $groups = Get-UnifiedGroup
      foreach($group in $groups){
      $name = $group.Name
      Add-UnifiedGroupLinks –Identity $name –LinkType Members –Links $admin
      Add-UnifiedGroupLinks –Identity $name –LinkType Owners –Links $admin

      }

Leave a Comment