As a SharePoint consultant I get asked all the time if there’s a way to rename (really repath) site collections. As SharePoint installations age, information architecture issues creep in. One of the ways this happens is that URL paths that were once correct no longer are. If the erroneous path is a web’s path, that’s easy enough to fix. You can use “stsadm –o renameweb” or Site Actions > Site Settings > Title, Description, and Logo. If you need to repath a site collection, well, that gets a little hairier. Okay, a lot hairier. There’s no way easy way to do it with out of the box tools. Before you say, “But, but, what about ‘stsadm –o rename’?” keep in mind that only works with hostname based site collections, and most site collections are path based. Yours are, I checked.
Since there’s no silver bullet we were reduced to workarounds. Normally that workaround looked like this:
- Backup site collection
- Delete site collection
- Restore site collection to new URL
- Pray, pray, pray
Not only was that process vulnerable to data loss from a bad backup or restore, it was very manual. As a general rule, I’m lazy and risk averse, so this process was bad for me.
I don’t know about you, but after the kids go to bed at night, I like to turn the lights down, pop some popcorn, put on some music, and cruise around in SharePoint 2013 looking for new PowerShell cmdlets to exploit. Friday nights at the Klindt household are cra-zy! One of the many, many new cmdlets I’ve recently fallen in love with is Copy-SPSite. Much like it sounds, it copies site collections. As we know, the only difference between a copy and a move is the delete at the end. Here’s the PowerShell I used to repath a site collection at http://portal.contoso.com/sites/blog to http://portal.contoso.com/sites/oldblog
As you can see, there’s nothing to moving the site collection, and even better there is no risk of losing data. You have the opportunity to check the copy is good before you delete the original site collection. I’ve done a little testing and Copy-SPSite seems to work great if the source and destination are in the same web application. If I try to copy a site collection to a different web application I get a weird error. That might be a limitation of the cmdlet. If so, it’s pretty easy to deal with. When you’re using Copy-SPSite you can specify a DestinationDatabase. You could copy the site collection to its own database, then move that database to a different web application.
While repathing site collections probably wasn’t the intended purpose of Copy-SPSite, it is one good use for it.