Changing SharePoint 2013 Site Collection URLs from Host-Named to Path-Based

Huge thankyou to Todd Klindt for saving me many many tears.

I have recently installed SharePoint 2013 August 2015 Cumulative Update, and one of the commands available as of the February 2015 Cumulative Update is the [site].Rename() method. This allows you to change the URL of your site from path-based (http://theweb/sites/myweb) to host-named (http://newweb.ishere). It’s a lot better than having to use Backup-SPSite and Restore-SPSite!

We had some databases that had been dismounted from their web application via Dismount-SPContentDatabase. I attached them to their new web application via:

Mount-SPContentDatabase -WebApplication http://the.webapp -Name DB_SiteCollection

This adds the content database to the web application and makes it available. In my case it became the “root” site collection as it was previously attached to a host-header web application (as opposed to a host-named site collection).

I then accessed the site via:

$db = Get-SPContentDatabase DB_SiteCollection $site = $db.Sites[0]

Renaming the site first of all using:


Gave me the following error:

Exception calling “Rename” with “1” argument(s): “Content database does not support renaming to and from host header site collections. Please upgrade content database to version ‘|0’.”

Oops! Forgot to upgrade it! No problem, just using the command:

Upgrade-SPContentDatabase -WebApplication http://the.webapp -Name DB_SiteCollection

Fixed up the version of the content database, then tried my rename command again. This time I got:

Exception calling “Rename” with “1” argument(s): “Cannot rename a site collection with recycled items. Empty the site recycle bin of site collection http://new-hnsc-url and retry.”

OK that makes sense. Recycle bin content would be pointing to different URLs after a site rename. Not sure why recycle bin content can’t be updated at the same time but whatever:


and then the previous $site.Rename() magic worked perfectly. That’s days of work saved thanks to a nice new function.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: