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. How about changing the subsite name in SharePoint Online? Well, set the “Title” field in the above page!

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"

$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
    #change subsite url sharepoint online powershell
    $web.ServerRelativeUrl = $NewURL
    Write-host "Sub-Site URL has been Changed to '$NewURL'" -ForegroundColor Green  
Catch {
    write-host -f Red "Error Changing Subsite URL!" $_.Exception.Message

Similarly, to change the subsite title, use:

$Web.Title = "New Name for the Site"

PnP PowerShell to Rename a SharePoint Online Subsite

Let’s walk through the steps necessary to change the URL of a subsite in SharePoint Online using PowerShell:

$NewName = "United States"
$NewURL="/sites/Retail/UnitedStates" #Relative URL

Try {
    #Connect to the Subsite
    Connect-PnPOnline -Url $SiteURL -Interactive
    #Get the subsite
    $Web = Get-PnPWeb
    #change subsite name and url
    $Web.Title = $NewName
    $Web.ServerRelativeUrl = $NewURL
    Write-host "Subsite has been Renamed!" -ForegroundColor Green  
Catch {
    write-host -f Red "Error Renaming Subsite!" $_.Exception.Message

To change the URL of a SharePoint Online site collection, use: How to Change the Site URL in SharePoint Online?

How to change the site name in SharePoint Online?

To change the site title of a SharePoint Online site collection, Browse to your SharePoint site where you want to change the name >> Click on Settings gear >> Choose “Site Information” link >> Enter the Site name value and hit Save to change the name to your SharePoint site.
More info: Change site title in SharePoint Online

How to rename a file in SharePoint Online?

The quickest way to rename a document is: Browse to the location where the files are located, Right-click on your desired File and Choose the “Rename” from its context menu (Or Select the File >> Click on the “Rename” button in the Toolbar). Provide a new name to the file in the Rename pop-up and click Save.
More info: Rename a Document 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!

Leave a Reply

Your email address will not be published.