Copy-SPSite: Clone SharePoint Site Collection using PowerShell

The Copy-SPSite is a new feature introduced in SharePoint 2013 that allows us to copy an existing site collection into a new site collection. Copy-SPSite cmdlet clones/duplicates an existing site collection into a new one. Optionally, You can specify the “Destination Database” parameter to copy the site collection into a new database.

Copy-SPSite Example:

Syntax: 

Copy-SPSite {Source-Site-Collection-URL} [-DestinationDatabase {Destination-Database-Name}] -TargetUrl {Target-Site-Collection-URL}

Example:

Copy-SPSite https://intranet.crescent.com/sites/sales -TargetUrl https://intranet.crescent.com/sites/sales2 -DestinationDatabase SP13_Intranet_ContentDB005

This gets you a duplicate of a site collection on a new URL!

Using Copy-SPSite cmdlet to rename existing site collection:

To rename site collections, we followed the backup-delete-restore process as in my other article: Rename site collection in SharePoint 2010 using PowerShell. Of course, there is a risk involved as you delete site collections – There are chances to lose data. Fortunately, SharePoint 2013 came with new functionality, “Copy-SPSite”. As the name suggests, It’s used to copy the SharePoint site under a new name (URL) without any risk of losing data!

Tips: Want to copy SharePoint site to another server? Use Backup-SPSite and Restore-SPSite cmdlets to copy site between farms!

Copy SharePoint site to another web application

While it’s straightforward to copy the site to different site collections, I had a few glitches while copying the SharePoint site to another web application. Copy SharePoint site to another web application using Copy-SPSite doesn’t work!
Copy-SPSite : The site collection being moved and the destination content database must be within the same Web application.

copy-spsite different web application

Solution:

Use Backup-SPSite and Restore-SPSite cmdlets!

Copying Host Named Site Collections
I tried to copy a SharePoint site to another on path-based site collections, and It went through well. But when I tried copying a host-named site collection, I ended up with an error!

Copy-SPSite -Identity 'https://sales.crescent.com' -TargetUrl 'https://sales2.crescent.com' -HostHeaderWebApplication 'https://hosting.com'

And got this error:
Copy-SPSite : Another site already exists at https://sales.crescent.com/. Delete this site before attempting to create a new site with the same URL, choose a new URL, or create a new inclusion at the path you originally specified.

copy-spsite site already exists

Workaround: Remove site URL and then run copy site!

Remove-SPSiteURL -URL https://your-hnsc-site-url
You can’t copy a site collection in SharePoint 2007/SharePoint 2010/SharePoint 2013 within the same content database!

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “Copy-SPSite: Clone SharePoint Site Collection using PowerShell

  • i, I tried to rename site using copy-spsite command, the command ran with no errors but there was no new site created. If I check Central Admin, I can see the new site url there, but it has no information and I cannot select and delete the site.
    I tried deleting using PS (remove-spsite), no luck. How do I delete this orphaned site?

    Reply
  • Very important notice at the bottom:
    You can’t copy a site collection in SharePoint 2007/SharePoint 2010/SharePoint 2013 within the same content database

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *