Skip to main content
SysAdmin

Manage Office 365 Group Members and Owners with PowerShell

By May 26, 2023June 27th, 2023No Comments

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:

1.  #Create credential object
2.  $credObject = Get-Credential
3.
4.  #Import the Exchange Online ps session
5.  $ExchOnlineSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credObject -Authentication Basic -AllowRedirection
6.  Import-PSSession $ExchOnlineSession

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

1.  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:

1.  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:

1.  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:

1.  Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members  –Links johndoe@contoso.com,janedoe@contoso.com
  • 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:

1.  Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links johndoe@contoso.com
2.  Add-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners –Links johndoe@contoso.com

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:

1.  Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners –Links johndoe@contoso.com -Confirm:$false
2.  Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links johndoe@contoso.com -Confirm:$false
3.
4.  #To remove only a member
5.  Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Members –Links janedoe@contoso.com -Confirm:$false