How to Add Owner to Office 365 Group using PowerShell?
Requirement: Add Owner to Office 365 group using PowerShell.
How to Set Group Owners in Office 365?
Office 365 groups are a powerful tool for collaboration and information sharing, and If you are managing Office 365 Groups, you may need to add an owner to the group. In this blog post, we will walk you through the process of adding an owner to an Office 365 group through the Microsoft 365 admin center. This can be done using PowerShell as well, so we’ll show you how to use PowerShell to add an owner to your Office 365 Group. We will also share the scripts you can use to make the process easier. Let’s get started!
To add members to Office 365 group through Microsoft 365 admin center, follow these steps:
- Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
- Expand “Teams & Groups” and Click on “Active Teams & Groups” in the left navigation.
- Search and Select the Office 365 group you wish to add an owner.
- In the Group details page, click on the “Members” tab and then pick “Owners”.
- Click on the “Add Owners” button at the top of the page.
- Search and select users you wish to add to the group >> Click on the “Add” button. Hit the close button once you are done!
Add Owner to Office 365 Group using PowerShell
To add a user as an owner of an Office 365 group, we need to add them as a “member” to the group first, and then we have to add the user as an owner. Use the Add-UnifiedGroupLinks cmdlet to add an owner to an Office 365 group using PowerShell. Provide the group’s email address and the owner’s email address as input.
#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False
#PowerShell to add Owner to office 365 group
Add-UnifiedGroupLinks -Identity "Purchase@crescent.com" -LinkType "Members" -Links "Mark@crescent.com"
Add-UnifiedGroupLinks -Identity "Purchase@crscent.com" -LinkType "Owners" -Links "Mark@crescent.com"
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False
Similarly, to add an Owner to All Office 365 groups, use the following:
#Parameter
$GroupOwner = "Mark@crescent.com"
#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False
#Get All Office 365 Groups and Add Group Owner
Get-UnifiedGroup -ResultSize Unlimited | ForEach-Object {
Add-UnifiedGroupLinks -Identity $_.Name -LinkType Members -Links $GroupOwner
Add-UnifiedGroupLinks -Identity $_.Name -LinkType Owners -Links $GroupOwner
Write-host "Added Owner to Group:"$_.DisplayName
}
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False
PnP PowerShell to Add Owners to Microsoft 365 Group
Use this PnP PowerShell script to add a group owner in Office 365.
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "HRAdmin@crescent.com"
$OwnerEmail = "Steve@crescent.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Office 365 Group from Email
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
#Get Owners of the group
$GroupOwners = Get-PnPMicrosoft365GroupOwners -Identity $Group | Select -ExpandProperty UserPrincipalName
#Check if group exists
If($Group -ne $Null)
{
#Check if the given user is already a Owner of the group
If($GroupOwners -notcontains $OwnerEmail)
{
#Set Owner to the Group
Add-PnPMicrosoft365GroupOwner -Identity $Group -Users $OwnerEmail
Write-Host "Group Owner Added Successfully!" -f Green
}
Else
{
Write-Host "User is already in the Group Owners List!" -f Yellow
}
}
Else
{
Write-host "Could not Find Group!" -f Yellow
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Add Owner to SharePoint Online Site Associated Office 365 Group:
So, you have just the site URL and want to add an owner to the associated group of a SharePoint Online site?
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/hr"
$GroupOwner = "Steve@crescent.com"
#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False
#Get the Office 365 group associated with the SharePoint site
$Group = Get-UnifiedGroup -ResultSize Unlimited | Where {$_.SharePointSiteUrl -eq $SiteURL}
#Add Owner to the group
Add-UnifiedGroupLinks -Identity $Group.Id -LinkType "Members" -Links $GroupOwner
Add-UnifiedGroupLinks -Identity $Group.Id -LinkType "Owners" -Links $GroupOwner
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False
PnP PowerShell to Add Owner to the Associated Microsoft 365 Group of the Site
As the Group connected site’s permissions are controlled at the Microsoft 365 group level, We have to add an owner at the group level!
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/CorporateBranding"
$SiteOwner= "Salaudeen@crescent.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Site
$Site = Get-PnPSite -Includes GroupId
#Add Owner to Microsoft 365 Group connected to the site
Add-PnPMicrosoft365GroupOwner -Identity $Site.GroupId -Users $SiteOwner
Write-host "`tAdded Owner to the Associated Microsoft 365 Group!" -f Green
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
Office 365: Change Group Owner using PowerShell
We can also set group owners with Azure AD cmdlets as well.
#Parameters
$GroupName = "Purchase"
$UserUPN = "Mark@crescent.com"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Add Group Owner
Add-AzureADGroupOwner -ObjectId (Get-AzureADGroup -SearchString $GroupName).ObjectId -RefObjectId $AADUser.ObjectId
To add members to Office 365 group, use: How to Add Members to Office 365 Group using PowerShell?
Conclusion:
In conclusion, adding an owner to an Office 365 group is a crucial task for managing access and permissions within an organization. As an administrator, you may need to add or remove owners from a group to manage its access and permissions. There are several ways to add an owner to a group, including using the Office 365 admin center, the Microsoft Teams admin center, and PowerShell. By following the steps outlined in this article, you can easily add an owner to an Office 365 group and ensure that the group is managed effectively. Remember to connect to the Exchange Online service before running the command and have the necessary permissions.
Hi, i wants to change the owner for sharedmailbox or usermailbox i used the below command:
(Add-MailboxPermission -Identity $SharedMailbox -Owner $user_mailid) but the owner is not changing still remains the same result, could anyone help me to sort it out.
I have a requirement to add different users as owners on different m365 groups (I have a spreadsheet of the owners and their respective groups).
Could you please assist with the script as well?
Thank You.
Does this work for distrbution lists as well?
Hi Salaudeen,
I have similar request where I have to add a user as M365 group owner. All I have is the user info with email address and list SPO sites. Could you please assist with the script. Thank you.
Sure, Post updated with the script to get the associated Office 365 group of a SharePoint Online site and add owner to it.