How to Add an Owner to an Office 365 Group using PowerShell?

Requirement: Add Owner to Office 365 group using PowerShell.

A Microsoft 365 Group is a collection of users who share a common set of resources, such as a shared mailbox, calendar, document library, and more. Microsoft 365 Group owners are responsible for managing the group’s settings, membership, and content. They can add or remove members, modify group settings, and ensure that the group is being used effectively and in accordance with the organization’s policies.

In this article, I will guide you through the process of adding an Office 365 Group owner, including various methods such as using the Microsoft 365 admin center and leveraging PowerShell for advanced management.

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!

The most straightforward method to add an owner to an Office 365 Group is through the Microsoft 365 admin center. Follow these steps to add a group owner:

  1. Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
  2. Expand “Teams & Groups” and Click on “Active Teams & Groups” in the left navigation.
  3. Search and Select the Office 365 group you wish to add an owner.
  4. In the Group details page, click on the “Members” tab and then pick “Owners”.
  5. Click on the “Add Owners” button at the top of the page.
    add owner to office 365 group using powershell
  6. Search and select users you wish to add to the group >> Click on the “Add” button. Hit the close button once you are done!
    how to add owners to an office 365 group

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
}

Add Microsoft 365 Group Owner using Microsoft Graph PowerShell

To add an owner to Microsoft 365 group using Microsoft Graph PowerShell, you can follow these steps:

  1. Connect to Microsoft Graph using the Connect-MgGraph cmdlet.
  2. Get the user object by using the Get-MgUser cmdlet and providing the user’s email address.
  3. Get the group object by using the Get-MgGroup cmdlet and providing the group’s ID.
  4. Add the group owner by using the Add-MgGroupOwner cmdlet and providing the group object and the user object.

Here’s an example PowerShell script that adds a group owner:

#Parameters
$UserID = "steve@crescnet.com"
$GroupName = "Human Resource"

#Connect to Microsoft Graph
Connect-MgGraph -Scopes Group.ReadWrite.All, User.Read.All

#Get the User
$User = Get-MgUser -Filter "UserPrincipalName eq '$UserID'"

#Get the Group
$Group = Get-MgGroup -Filter "DisplayName eq '$GroupName'"

#Add Group Owner
New-MgGroupOwner -GroupId $Group.ID -DirectoryObjectId $User.ID

Microsoft 365: Add Group Owner using Azure AD PowerShell

We can also add 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

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.

To add members to an Office 365 group, use: How to Add Members to Office 365 Group using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “How to Add an Owner to an 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

Your email address will not be published. Required fields are marked *