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 need to transfer ownership of a site 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!
Site Owners of a SharePoint Online site collections can be changed only through SharePoint Online Admin Center or PowerShell. To change site owner in SharePoint Online, follow these steps:
- Sign in to Office 365 Admin Center (https://portal.office.com/), click on “SharePoint Admin Center” link from “Admin Centers” section.
- You’ll be landing to Site Collections list in 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 for primary site collection administrator and Click on Save button once you are done with your changes.
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 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 certain sites like Search center, app catalog, etc.
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.
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
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.
True! Looks this property has changed over time. Post has been updated.
Do you have PowerShell for changing site owner of on-prem sharepoint server?
Here you go: How to Change Site Collection Primary and Secondary Administrators in SharePoint?