SharePoint Online: How to Change Subsite URL using PowerShell?

Requirement: Change the URL of a subsite in SharePoint Online.

How to Change the Subsite URL in SharePoint Online?

In this blog post, I am going to show you how to change the URL of a SharePoint Online subsite. There are two different ways to do this, and I will show you two methods. The first method is the easiest, from the web browser interface, and the second method is with PowerShell.

To rename a site URL in SharePoint Online, follow these steps:

  • Click on Settings Gear Icon >> Choose “Site Information” and then “View All Site Settings”
  • Click on “Title, description, and logo” under the “Look and Feel” group
  • Enter the new URL for the subsite and click on “OK”
    sharepoint online change url of subsite

This renames subsite URL in SharePoint Online.

PowerShell to Change Subsite URL in SharePoint Online

Here is the PowerShell to change the URL of a SharePoint Online Subsite:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables
$SiteURL="https://Crescent.sharepoint.com/sites/marketing/us"
$NewURL="/sites/marketing/UnitedStates" #Relative URL

Try {
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get the Sub-Site
    $Web = $Ctx.web
    $Ctx.Load($web)
    $Ctx.ExecuteQuery()
 
    #change subsite url sharepoint online powershell
    $web.ServerRelativeUrl = $NewURL
    $Web.Update()
    $Ctx.ExecuteQuery()
     
    Write-host "Sub-Site URL has been Changed to '$NewURL'" -ForegroundColor Green  
}
Catch {
    write-host -f Red "Error Changing Subsite URL!" $_.Exception.Message
}

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply