Copy-SPSite – Clone SharePoint Site Collection using PowerShell

Copy-SPSite is a new feature introduced in SharePoint 2013, allows us to copy an existing site collection into a new site collection. Copy-SPSite cmdlet clones/duplicates 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 http://intranet.crescent.com/sites/sales -TargetUrl http://intranet.crescent.com/sites/sales2 -DestinationDatabase SP13_Intranet_ContentDB005

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

Using Copy-SPSite cmdlet to rename existing site collection:

To rename site collections, we used to follow 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 make a copy of 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 simple and straightforward to copy the site to different site collections, I had 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, It went through well. But when I tried copying a host-named site collection, ended up with an error!

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

And got this error:
Copy-SPSite : Another site already exists at http://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 http://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 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!

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

  • June 9, 2015 at 8:46 PM

    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
  • April 23, 2015 at 2:15 PM

    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