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?

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

  • Login to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  • Expand Groups and Click on Groups link in the left navigation. 
  • Search and Select the Office 365 group you wish to add owner.
  • In the Group details page, Click on “Members” tab >> Click on View all and manage Owners link. 
  • Click on “Add Owners” button on the top of the page >> Search and select users you wish to add to the group >> Hit “Save” button once done!
    add owner to office 365 group powershell

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 owner.

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#PowerShell to add Owner to office 365 group
Add-UnifiedGroupLinks -Identity "[email protected]" -LinkType "Members" -Links "[email protected]"
Add-UnifiedGroupLinks -Identity "[email protected]" -LinkType "Owners" -Links "[email protected]"

#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False

Similarly, to add Owner to All Office 365 groups, use:

#Parameter
$GroupOwner = "[email protected]"

#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

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 = "[email protected]"

#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= "[email protected]"

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 = "[email protected]"

#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?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

5 thoughts on “How to Add Owner to Office 365 Group using PowerShell?

  • 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.

    Reply
  • 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.

    Reply
  • 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.

    Reply
    • Sure, Post updated with the script to get the associated Office 365 group of a SharePoint Online site and add owner to it.

      Reply

Leave a Reply