3 Different ways to Change Site Collection URL in SharePoint 2013/2016 using PowerShell

In this SharePoint administration tutorial, we will discuss 3 different ways to change site collection URL in SharePoint 2013/2016 using PowerShell & STSADM.

Few times you may get the requirement to change the site collection URL in SharePoint 2013/2016 using PowerShell.

If you are new to PowerShell, you can read an article on Working with PowerShell in SharePoint Online/2016/2013.

Change site collection url sharepoint 2013 powershell

There are three different ways we can change the site collection URL in SharePoint 2013/2016.

Change site collection URL in SharePoint 2013/2016 PowerShell

There is a very easy way to change the site collection URL in SharePoint 2013/2016 using PowerShell.

Below is the PowerShell script to change the site collection URL in SharePoint.

Note: You need to do an IISREST after running this PowerShell command.

$site = Get-SPSite http://rajkiran/sites/Oldsite

Change site collection URL in SharePoint 2013 (PowerShell)

This example makes a copy of the http http://rajkiran/sites/Oldsite site collection from its database to the WSS_Content database with the new URL, http://rajkiran/sites/Newsite   and a new Site ID. 

Here we will use the PowerShell script to backup, restore and then remove the old SharePoint 2016/2013 site collection using PowerShell.

You can use remove SP Site command to remove the old site collection

Remove-SPSite -Identity http://rajkiran/sites/Oldsite ' -GradualDelete -Confirm:$False

You can also use backup and restore option to get the same site collection different place.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  

#Get the Source Site Collection URL  
$sourceURL = Read-Host http://Rajkiran.tets.com/sites/source  
#Get the Target Site Collection URL  
$targetURL = Read-Host http://Rajkiran.tets.com/sites/destination  

#Location for the backup file  
$backupPath = Read-Host “Enter the Backup File name & location (E.g. D:\Raj\Source.bak):”  
#Set the Error Action  
$ErrorActionPreference = "Stop"  

Write-Host "Backing up the Source Site Collection..."-ForegroundColor DarkGreen  
Backup-SPSite $sourceURL -Path $backupPath -force  
 Write-Host "Backup Completed!`n"  

#Delete source Site Collection  
Write-Host "Deleting the Source Site Collection..."  
Remove-SPSite -Identity $sourceURL -Confirm:$false  
Write-Host "Source Site Deleted!`n"  

#Restore Site Collection to new URL  
Write-Host "Restoring to Target Site Collection..."  
Restore-SPSite $targetURL -Path $backupPath -Confirm:$false  
Write-Host "Site Restored to Target!`n"  

#Remove backup files  
Remove-Item $backupPath  
Write-Host "Operation Failed. Find the Error Message below:" -ForegroundColor Red  
Write-Host $_.Exception.Message -ForegroundColor Red  
#Reset the Error Action to Default  
$ErrorActionPreference = "Continue"  

write-host "Process Completed!"

Rename Site Collection URL using Backup and Restore the Site Collection (STSADM)

We can also rename the site collection URL using backup and restore site collection option using STSADM tool. In SharePoint 2007(MOSS)/2010, you can use STSADM command to rename Site collection URL.

Backup the Source Site collection Using STSADM command:

stsadm -o backup -url http://Rajkiran.tets.com/sites/source -overwrite -filename source.bak

Delete the Source Site collection using STSADM command (It’s mandatory otherwise you will get an error message)

stsadm -o deletesite -url http://Rajkiran.tets.com/sites/source

Restore Site Collection Backup with Targeted URL

stsadm -o restore -url http://Rajkiran.tets.com/sites/destination -filename source.bak

You may like following SharePoint PowerShell tutorials:

Hope this PowerShell SharePoint tutorial helps to change the site collection URL using PowerShell in SharePoint 2013/2016.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

  • >