DEV Community

Experts Inside

How do I rename a SharePoint Online site using PowerShell?

plamber profile image Patrick Lamber ・2 min read

A SharePoint Online administrator can change the SharePoint Online site address. The interesting part of this feature is that in many situations Microsoft already considered how to limit the impact of such a change. Nevertheless, you should have a look into the effects of changing a site address before performing any operation.

I created a sample script that shows you how to use PowerShell to perform a site change.

## Install the SharePoint Online Management Module if required
## Install-Module -Name Microsoft.Online.SharePoint.PowerShell 
## More info under

## parameters start
$tenant = "yourTenantName"
$sourceAlias = "aliasOfYourSource"
$targetAlias = "aliasOfYourTarget"
## parameters end

# Connect to SPO and perform the site rename
Connect-SPOService "https://$"
$oldUrl = "https://$$sourceAlias"
$newUrl = "https://$$targetAlias"

# Perform the site rename
Start-SPOSiteRename -Identity $oldUrl -NewSiteUrl $newUrl

# The process might take a while depending the size of the site. You can check the status using this command
Get-SPOSiteRenameState -Identity $oldUrl

# By using the standard parameters of Start-SPOSiteRename, a successful site rename will provision  After a successfull site rename a new site with the template 'RedirectSite#0' is created

$site = Get-SPOSite $oldUrl

From the script, you can see that the operations are triggered by using the Start-SPOSiteRename command. This will queue a rename job that will be executed in the background. The command Get-SPOSiteRenameState will return you the current status of the job. Once the job is marked as completed, you will have two sites in your tenant. You will have the site with the new URL and contents and a new site using the Template Redirect#0. This site will ensure that all requests pointing to the old URL will be redirected to the new URL. This site also ensures that nobody is able to request a new site with the old URL.

In case you want to free up the old name, delete the site collection that has been created for redirection.


Editor guide