Add or Remove Members and Owners in Office 365 Group using Powershell

We can use the Add-UnifiedGroupLinks cmdlet to add members and owners to an Office 365 Group and remove members and owners from unified group using the Remove-UnifiedGroupLinks cmdlet. Both the cmdlets 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

Before proceed, run the following commands to connect Exchange Online Powershell session.

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

Add Members and Owners to Office 365 Group

This example add the member [email protected] to the Office 365 Group named TestO365Group. We need to set the parameter LinkType as Members to add users as member.

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

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

Add multiple users as member:

Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members  –Links [email protected],[email protected]

Add an user as owner: To add an user as a owner to office 365 group, first we need to add the user as a member to the specified group and then we have to add the user as owner.

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

Remove Members or Owners from Office 365 Group

This example removes the member [email protected] and [email protected] from the Office 365 Group named TestO365Group..

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

Remove owner: To remove an owner from the group, first you have to remove user from the LinkType Owners and remove the user from the LinkType Members.

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

Add or Remove 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 "TestO365Group" –LinkType Members  –Links $_.member
}

List members or owners of a group

Once we added or removed members or owners, we can use the 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 "TestO365Group" –LinkType Members

List owners of a group.

Get-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Owners

Advertisement

3 thoughts on “Add or Remove Members and Owners in Office 365 Group using Powershell”

  1. Morgan, excellent page! Question, how do you use this to add "mail contacts" that are already in your exchange contacts. I cannot seem to make it work.

    Reply

Leave a Comment