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
How do you add a person as an Owner but not a Member?
You can do this in Azure but not in Powershell that I know?
It’s explained under the section “Adding Member and Owners to an Office 365 Group”. Basically, first, add them as members and then upgrade to owner.
and you have forget this
Getting all O365 Groups as person is a member of
Get-UnifiedGroup | Where-Object { (Get-UnifiedGroupLinks $_.Alias -LinkType Members | foreach {$_.Name}) -contains “User Name”}
how to change the role of a user from Owner to member?
Just remove the owner role:
Remove-UnifiedGroupLinks –Identity "O365GroupName" –LinkType Owners –Links [email protected] -Confirm:$false
Yes. I need to remove my name from ALL groups and place the name of the Global Admin as the Owner.
I will look into it this week.
How can I add a user to All groups as an owner ?
$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
}