Home > PowerShell, SharePoint 2010, SharePoint Administration > Moving SharePoint 2010 Site Collections Between Managed Paths using PowerShell

Moving SharePoint 2010 Site Collections Between Managed Paths using PowerShell

Moving Site Collections between Managed Paths in SharePoint 2010 is a two to three step process.  I wish It was as simple as moving a Site Collection between content databases, which basically is a one line PowerShell script.  Granted its not very hard to move between Managed Paths it just takes time depending on the size of your Site Collection.  If its a rather large Site Collection it can take some time to move.

Below is the script to successfully move a Site Collection between Managed Paths.  Microsofts Best Practices is to have less than 20 Managed Paths in a given Web Application, having more will affect system performance.  In my current environment I had 25 Managed Paths in one dedicated Web Application (that was to much) so I needed to move these Site Collections from their explicit Managed Path to a wildcard managed path i.e (/sites/) instead.

Before you get started make sure your managed path you want to move to already exists.  I will update this script later to ask the user if they want to create a managed path before moving.

————————————————————————————————————————————————–
#Get the from Site Collection URL
$fromURL = Read-Host “Site Collection To-Move URL”
#Get the to Site Collection URL

$toURL = Read-Host “Site Collection Move-To URL”

#This is not necessarily needed, I did this just in case you want your Site Collection to live in the same database after the move, in most cases the Site Collection will be placed back into the same DB.
$Database = Get-SPContentdatabase -Site $fromURL

#Location to the backup file directory to store Site Collection backup files
$backupPath = Read-Host “Location you want to save backup files”

#Backing up Site Collection prior to moving
Write-Host “Backing Up Site Collection….”

Backup-SPSite $fromURL -Path $backupPath -force

#Removing Site Collection from old managed path
Write-Host “Removing Site Collection from old managed path location…”

Remove-SPSite -Identity $fromURL -Confirm:$false

#Restoring Site Collection to new Managed Path
Write-Host “Restoring Site Collection to new managed path location…”

Restore-SPSite -Identity $toURL -Path $backupPath -Confirm:$false

#Remove backup files from the backup dirctory
Remove-Item $backupPath

#Remove Managed Path from Web Application
$removeManagedPath = “Name of Managed Path to Delete”
Write-Host “Deleting $removeManagedPath managed path”
Get-SPWebApplication | Remove-SPManagedPath $removeManagedPath -Confirm:$false

—————————————————————————————————————————————————

Advertisements
  1. March 22, 2013 at 9:41 am

    Nice post. Here is the one more post explaining Managed path in Sharepoint

    http://sureshpydi.blogspot.in/2013/03/share-point-managed-paths.html

    • March 22, 2013 at 9:50 am

      Thanks Suresh,

      I’m vary familiar with managed paths, but thanks for sharing, this could be helpful for those that are not!

      v/r
      JShidell

  2. April 12, 2013 at 8:25 am

    #Restoring Site Collection to new Managed Path
    Write-Host “Restoring Site Collection to new managed path location…”
    Restore-SPSite -Identity $toURL $backupPath -Confirm:$false

    This should be:

    #Restoring Site Collection to new Managed Path
    Write-Host “Restoring Site Collection to new managed path location…”
    Restore-SPSite -Identity $toURL -Path $backupPath -Confirm:$false

    Otherwise if you run the script as is, your backup file will get deleted somehow, and having just removed the site collection you hope that your DR strategy and common sense in validating each line one by one will prevail… I did lose a backup but luckily was being cautious and didn’t lose anything!

    Thanks for the tips.

    • April 15, 2013 at 8:30 am

      Hi Gus,

      You are correct, and the -Path cmdlet is suppose to be part of that Restore statement. I just forgot to add it, when I wrote out this blog. Thanks for the catch.

  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: