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

Requirement: Change Site Owner in SharePoint Online using PowerShell

How to Change Site Owner in SharePoint Online?

In this blog post, we are going to 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!
  • Sign in to Office 365 Admin Center (https://portal.office.com/), and click on the “SharePoint Admin Center” link from the “Admin Centers” section. 
  • 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. 
  • 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”.
  • 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.
  • 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 Administrators”.

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?

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 owner of the group from the Admin Center.

  • Login to SharePoint Admin Center >> Select the group site
  • Click on “Permissions” from the toolbar >> Manage Group Owners
  • 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 group owner to all Microsoft 365 group connected sites, use:

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

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

Leave a Reply

Your email address will not be published.