How to replace root site in SharePoint Online from Microsoft 365 Admin Center

How to replace root site in SharePoint Online from Microsoft 365?

No comments

 4,878 total views,  10 views today

In this article, we will learn about how to replace the root site in SharePoint online from the Microsoft 365 (Office 365) admin center. This option was not available earlier, I would say this is a huge improvement towards a better intranet for the user. With this addition, we can have our own custom branded site, later on, we can convert the branded site to a tenant root site.

For example, for any subscription when we create a tenant for SharePoint Online – the default root site URL would be in the below format:

Format: https://tenantname.sharepoint.com
Example: https://globalsharepoint2020.sharepoint.com

For this demo, I have created another communication site as – https://globalsharepoint2020.sharepoint.com/sites/home, we are going to replace the site with a tenant root site – meaning after replacing if the user types the https://globalsharepoint2020.sharepoint.com, the new home site will be opened.

Please see the below screenshot, where we have shown two sites:

  1. https://globalsharepoint2020.sharepoint.com – tenant current root site
  2. https://globalsharepoint2020.sharepoint.com/sites/home – future root site
Replace root site in SharePoint Online tenant
Replace root site in SharePoint Online tenant

Steps to replace the root site in the SharePoint admin center

Assume that you have a global administrator or SharePoint administrator role for your tenant and have opened the SharePoint admin center URL.

Note:

Step1: Select your current root site as shown below.

Step 2: Click on the three dots (…) in the menu.

Step 3: Click on the “Replace site” link from the dropdown list.

Replace site in SharePoint admin center
Replace site in the SharePoint admin center

Step to pass the site URL parameter – URL of the site you want to use

In the next right-side panel we will get the “Replace root site” configuration page where it will be mentioned in the below text:

“Specify a different site to use as the root (top-level) site for your organization. The site you select must be a team site or communication site. It can’t be a hub site or connected to a Microsoft 365 Group.”

Replace site in SharePoint admin center process
Replace site in SharePoint admin center process

Then we need to pass the below parameter:

Note:

Step to check the site validation

Here the tool will check whether this site can be replaced as a new root site – internally it will check all prerequisites to become a root site, if everything goes well, we will see this message “This site can be used as the root site – site validation” in green color which indicates that the site is ready for the swap.

This site can be used as the root site - site validation
This site can be used as the root site – site validation

Click on the “Save” button.

Note

Immediately on the next screen, we will see the status message as “Replacing root site” (as shown below).

Replacing root site in progress in SharePoint Online admin center
Replacing root site in progress in SharePoint Online admin center

Now we could see that no more the old root site is in an active state – now it has been archived (as shown below).

Old root site has been archived after replacing it in SharePoint Online admin center
The old root site has been archived after replacing it in the SharePoint Online admin center

Now onwards if you browse your tenant root site it will be redirected to the new root site.

Now, we will show you a couple of screenshots.

Before swapping the site the new home site was as below:

SharePoint Online home site before swapping
SharePoint Online home site before swapping

After swapping the site – refresh the same page, we will be redirected to the tenant root site URL as below:

SharePoint Online tenant root site after swapping
SharePoint Online tenant root site after swapping

The old tenant root site has been archived after the swapping as shown below:

SharePoint Online tenant root site has been archived after swapping
SharePoint Online tenant root site has been archived after swapping

How to swap the root site in SharePoint Online using PowerShell?

The swap whatever we have using the Microsoft 365 admin tool (SharePoint Online Administration) user interface, we can do the same swapping of the root site using the below PowerShell script in SharePoint Online:


####The below script is used to swap the old root site to new home root site.

cls

$PSshell = Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorVariable err -ErrorAction SilentlyContinue
if($PSshell -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "SwapRootSiteUsingPowerShell"

#'yyyyMMddhhmm yyyyMMdd
$enddate = (Get-Date).tostring("yyyyMMddhhmmss")
$logFileName = $fileName +"_"+ $enddate+"_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path

$directoryPathForLog=$directoryPath+"\"+"LogFiles"
if(!(Test-Path -path $directoryPathForLog))
{
New-Item -ItemType directory -Path $directoryPathForLog
#Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}

$logPath = $directoryPathForLog + "\" + $logFileName

$isLogFileCreated = $False

function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}

 

#Paramaters area
$adminSiteURL="https://globalsharepoint2020-admin.sharepoint.com"
$sourceSiteURL="https://globalsharepoint2020.sharepoint.com/sites/Home"
$targetURL="https://globalsharepoint2020.sharepoint.com"
$archiveURL="https://globalsharepoint2020.sharepoint.com/sites/archive-2021-05-25T112415Z"
$userName = "YourSPOUserName"
$passWord = "YourSPOPassword"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord

#Paramaters area - Ends

try
{

Connect-SPOService -Url $adminSiteURL

#Command Syntax

#Invoke-SPOSiteSwap -SourceURl "https://yourdomain.sharepoint.com/sites/home" -TargetURL "https://yourdomain.sharepoint.com" -ArchiveUrl "https://yourdomain.sharepoint.com/sites/archivedhome"

#Command example
Invoke-SPOSiteSwap -SourceUrl $sourceSiteURL -TargetUrl $targetURL -ArchiveUrl $archiveURL

Write-Host "The site has been swapped Successfully" -BackgroundColor Green


}
catch
{

$ErrorMessage = $_.Exception.Message +"in swapping the site!:"
Write-Host $ErrorMessage -BackgroundColor Red
Write-Log $ErrorMessage

}

Here the “Invoke-SPOSiteSwap” command does the job, the syntax of the command is as below:


Invoke-SPOSiteSwap -SourceURl "https://yourdomain.sharepoint.com/sites/home" -TargetURL "https://yourdomain.sharepoint.com" -ArchiveUrl "https://yourdomain.sharepoint.com/sites/archivedhome"

Notes:

  • The account that is executing the script should be a global administrator.
  • The home site must be a modern communication site.
  • The SharePoint Online Management Shell must be installed in the machine where you are executing the script – it can be downloaded from here.

General use cases of swapping of root site in SharePoint Online

Let’s say you have created a new modern communication site where you did a lot of customization in order to align with your company’s policy or in the existing modern communication site you have done the customization and that site you want to represent as your company’s home site – then we can make use of the swapping functionality.

Summary: What we had here?

Thus, in this article, we have learned the below with respect to swapping the root site in SharePoint Online:

  • In 2 steps replace/swap the root site in SharePoint Online using Microsoft 365 and PowerShell.
  • How to replace the root site in SharePoint Online from Microsoft 365?
  • How to swap the root site in SharePoint Online from Microsoft 365?
  • How to swap the root site in SharePoint Online from Microsoft 365?
  • How to swap the root site in SharePoint Online using the PowerShell command/script.
  • How to use the “Invoke-SPOSiteSwap” command in SharePoint Online?
  • Use cases of swapping of root site in SharePoint Online

See Also:

You may also like the following SharePoint PowerShell tutorials:

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:


Buy SharePoint Online & Office 365 Administration eBook