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.
1 2 3 | $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 morgan@contoso.com to the Office 365 Group named TestO365Group. We need to set the parameter LinkType as Members to add users as member.
1 | Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links morgan @contoso .com |
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:
1 | Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links alexw @contoso .com,alland @contoso .com |
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.
1 2 | Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links morgan @contoso .com Add-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Owners –Links morgan @contoso .com |
Remove Members or Owners from Office 365 Group
This example removes the member alexd@contoso.com and alland@contoso.com from the Office 365 Group named TestO365Group..
1 | Remove-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links alexw @contoso .com ,alland @contoso .com -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.
1 2 | Remove-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Owners –Links morgan @contoso .com -Confirm : $false Remove-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members –Links morgan @contoso .com -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.
1 2 3 | 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.
1 | Get-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Members |
List owners of a group.
1 | Get-UnifiedGroupLinks –Identity "TestO365Group" –LinkType Owners |
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.
Sorry Add-UnifiedGroupLinks do not support to add mail contacts. You can refer this great post "https://www.petri.com/office-365-groups-mail-contacts" to know more about "Office 365 Groups Support Mail Contacts as Guest Members"
Good article once aցain. I am ⅼooking forward for уоur next post:)