SharePoint Online: How to Change Site Owner (Primary Admin) using PowerShell?

Requirement: Change the Site Owner in SharePoint Online using PowerShell.

How to Change Site Owner in SharePoint Online?

In this blog post, we will show you how to change the primary site owner in SharePoint Online. This can be useful if you want to transfer site ownership to someone else. We will walk you through the process step by step and show you how to change the site owner in SharePoint Online using PowerShell. Let’s get started!

How do I change ownership of a SharePoint Online site? Site Owners of a SharePoint Online site collection can be changed through SharePoint Online Admin Center or PowerShell. To change site owner in SharePoint Online, follow these steps:

Important: You must be either Global Administrator or SharePoint Online Administrator to change site owners in SharePoint Online!
  1. Sign in to Office 365 Admin Center (https://portal.office.com/), and click on the “SharePoint Admin Center” link from the “Admin Centers” section. 
  2. You’ll be landing in the Site Collections list in the SharePoint Admin center (https://YourDomain-admin.sharepoint.com/_layouts/15/online/SiteCollections.aspx) with all site collections listed. 
  3. Select the site collection from the list of site collections to which you want to change the site owner >> From the ribbon, click on “Permissions” and then “Manage Admins”.
  4. On the “Manage Administrators” panel, You can change the primary site collection administrator – Site owner by setting them as “Primary Admin”. You can also configure additional site collection administrators.
  5. Enter the name of the primary site collection administrator and Click on the Save button once you are done with your changes.
    change site owner sharepoint online powershell

You can add only ONE site owner (Primary Site Collection Admin) in SharePoint Online! There is no secondary admin in SharePoint Online, but you can add more than one “Site collection Administrator”.

Now, let’s see how to change the site owner in SharePoint Online using PowerShell.

Change Site Owner SharePoint Online using PowerShell

We can change the site owner using the Set-SPOSite cmdlet. Here is an example: Set the variables according to your environment.

#Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$SiteCollURL="https://Crescent.sharepoint.com/Sites/marketing"
$SiteOwner = "[email protected]"
 
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
 
#sharepoint online powershell set site owner
Set-SPOSite -Identity $SiteCollURL -Owner $SiteOwner -NoWait

Please note, You should use this only for Non-Group connected sites. If you execute this script on a Microsoft 365 group-connected site, It will set the given user as the site owner and remove the existing Office 365 group from the Site owner permissions.

Change Site Owner for All Non-Group Connected Sites in the Tenant:

Make sure you set the parameters according to your environment and run the script. This cmdlet prompts you for credentials. Enter the Administrator’s credentials.

#Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
$SiteOwner= "[email protected]"

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)

#Get All site collections - Excluding certain templates and Group sites
$SiteCollections = Get-SPOSite -Limit All | Where { $_.Template -NotIn ("SRCHCEN#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1","GROUP#0")}

#Loop through each site collection
ForEach($Site in $SiteCollections)
{
   #sharepoint online powershell change site owner
   Set-SPOSite -Identity $Site.url -Owner $SiteOwner
   Write-host "Added Site Owner to "$Site.Url
}

This script updates the Site Owner for all site collections – excluding group sites and specific sites like Search center, app catalog, etc.

This article talks about adding a primary admin AKA primary site owner to a SharePoint Online site. In case, You are looking for adding someone to the Site Owner’s group with ‘Full control’ permissions, use: How to Grant Site Owner Permissions to a User in SharePoint Online using PowerShell?

PnP PowerShell to Set Site Owner in SharePoint Online

Use this PnP PowerShell script to set the site owner for a SharePoint Online site.

#Parameters
$AdminCenterURL ="https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/purchase"
$SiteOwner = "[email protected]"

#Connect to Admnin Center
Connect-PnPOnline -Url $AdminCenterURL -UseWebLogin

#Get the Site
$Site  = Get-PnPTenantSite -Url $SiteURL

#Update the Site Owner
$Site.Owner = $SiteOwner
$Site.Update()
Invoke-PnPQuery

Managing Site Owner for Microsoft 365 Group-Connected Sites

In Microsoft 365 group-connected sites, the site owner is set to Group owner by default. So, to add a group owner, You have to add the user as the group’s owner from the Admin Center.

  1. Login to SharePoint Admin Center >> Select the group site.
  2. Click on “Permissions” from the toolbar >> Manage Group Owners.
  3. Add a new user to the Owner list of the Group.
add group owner for sharepoint online site

PnP PowerShell to Add Owner to Associated Microsoft 365 Group

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! Here is how:

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

To add a group owner to all Microsoft 365 group-connected sites, use the following:

#Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com"
$SiteOwner= "[email protected]"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $AdminCenterURL -Interactive
 
    #Get all Microsoft 365 Group connected Sites
    $Sites = Get-PnPTenantSite | Where { $_.Template -like 'GROUP*'}

    #Iterate through sites and set site owner
    ForEach($Site in $Sites) 
    { 
        #Add Owner to Microsoft 365 Group connected to the site
        Add-PnPMicrosoft365GroupOwner -Identity $Site.GroupId -Users $SiteOwner
        Write-host -f Green "Added Owner to the Associated Microsoft 365 Group for "$Site.url
    }
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
}

Here is another post on adding site collection administrators to SharePoint Online: PowerShell to Add Site Collection Administrators in SharePoint Online

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

9 thoughts on “SharePoint Online: How to Change Site Owner (Primary Admin) using PowerShell?

  • Hello, first time commentor, long time reader. Do you know if there is a PNP equivelant of Set-SPOSite -Identity $SiteCollURL -Owner $SiteOwner ?

    I’ve tried the following but apparently it is a read only property. Surely there is an answer here… Maybe not?

    $site = Get-pnptenantsite -url “siteurlhere”
    $Site.Owner = “NewOwner”
    $Site.Update()

    Reply
    • Hi Nick,
      Post has been updated with the PnP PowerShell script to set site owner. Make sure you have SharePoint Online Admin permissions and installed the PnP.Powershell module.

      Reply
      • Im getting the same error as Nick that when doing $Site.Owner = $SiteOwner it errors InvalidOperation: ‘Owner’ is a ReadOnly property.
        Our sharepoint sites use the classic mode so dont have 365 groups assigned to them so adding the owner a group level is out.
        Any suggestions?
        I have Admin permissions and the latest PnP.Powershell module installed

        Reply
        • Workaround i found to use PNP and set primary owner was:
          Create the site with New-PnPTenantSite with whatever user you want
          Then add the group you want to be the primary owners by running
          Set-PnPTenantSite -Identity $URL -Owners “Group Name”
          Then remove all the other users with
          Get-PnPUser | ? Title -ne “Group Name” | Remove-PnPSiteCollectionAdmin

          Reply
  • Your PnP POSH example didn’t work for me, getting error “Failed to add user admins to site collection admins – ‘Owner’ is a ReadOnly
    property.”. Looking into PnP POSH Github, looks like the Owner property only has a getter, so this seems accurate.

    Reply
      • Unfortunately it can’t. I am also getting “‘Owner’ is a ReadOnly property” error

        Reply
  • Do you have PowerShell for changing site owner of on-prem sharepoint server?

    Reply

Leave a Reply

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