Many of clients have multiple site collection stored in the same content DB of the web application. And in some day, they will discover that one of site collection contents is growing so fast, and they decide to have a dedicated Content DB for this Site Sollection. Also they may want to change the Managed Path (url) of site, i.e.: from “http://hostheader/sites/sitename” to “http://hostheader/sitename”.
In this article, I will explain how I did these requirements in the following scenario:
1. I have a web application with url (http://sps:1), and all site collection under this web application shared the same Content DB (Name: WSS_SP01_Content_01)
2. I have 2 Site Collection (Host Header Root Site and HR Site):
- Main portal Site Collection under Host Header Root Managed Path (/)
- HR portal site collection under the managed path (/sites/hr/)
- I want to move the “HR” site to a new Content DB called(WSS_SP01_HR_Content_01)
- I want to change the url from (/sites/hr/) to (/hr/).
The Steps are (using PowerShell):
1. Open PowerShell – SharePoint 2010 Management Shell
2. Create Explicit Managed Path for target Web Application, and call it “hr”
- Enter the following line in PowerShell:
New-SPManagedPath -RelativeURL “hr” -WebApplication “http://sps:1” –Explicit - The PowerShell Results are:
- Check it from Central Administration > Manage Web Applications > Managed Path:
3. Create a new Content DB called “WSS_SP01_HR_Content_01”
- Enter the following line in PowerShell
New-SPContentDatabase -name “WSS_SP01_HR_Content_01” -WebApplication “http://sps:1” -MaxSiteCount 1 -WarningSiteCount 0 - Max Site Count = 1, to make sure No farther Site Collection can be added to this Content DB
- The PowerShell Results are:
- Check it from Central Administration > Manage Web Applications > Managed Content Databases:
4. Back up Site Collection “/sites/hr” to prepare moving it
- Enter the following line in PowerShell::
Backup-SPSite “http://sps:1/sites/hr” -Path “C:\HR_TempSC.bak” –force
- Check the file on “C” Drive
5. Removing the Site Collection from old managed path
- Enter the following line in PowerShell::
Remove-SPSite -Identity “http://sps:1/sites/hr” -GradualDelete -Confirm:$false - Check the current number of Site Collection of Main Content DB (WSS_SP01_Content_01) , It should be 2 ( minus the HR Site Collection)
6. Restoring Site Collection to new Managed Path “/hr”
- Enter the following line in PowerShell::
Restore-SPSite “http://sps:1/hr” -Path “C:\HR_TempSC.bak” -DatabaseServer “SPS” -DatabaseName “WSS_SP01_HR_Content_01” -GradualDelete -Force -Confirm:$false - Check the current number of Site Collection of Main Content DB (WSS_SP01_HR_Content_01), It should be “1”
7. Remove the backup files from the backup directory
- Enter the following line in PowerShell:
Remove-Item “C:\HR_TempSC.bak”
8. Check the old url of HR, It should be not exists
9. Check the new HR Site Collection url “http://sps:1/hr” :
10. Check the Site Collection Properties, Central Admin > Application Management > View all site collections
Conclusion
I move and change the managed path of the site collection as simple as described before using PowerShell script. It is easy, clear, and save my time. and the following is the list of scripts i used in article:
- New-SPManagedPath -RelativeURL “hr” -WebApplication “http://sps:1” -Explicit
- New-SPContentDatabase -name “WSS_SP01_HR_Content_01” -WebApplication “http://sps:1” –MaxSiteCount 1 -WarningSiteCount 0
- Backup-SPSite “http://sps:1/sites/hr” -Path “c:\HR_TempSC.bak” -force
- Remove-SPSite -Identity “http://sps:1/sites/hr” -GradualDelete -Confirm:$false
- Restore-SPSite “http://sps:1/hr” -Path “C:\HR_TempSC.bak” -DatabaseServer “SPS” -DatabaseName “WSS_SP01_HR_Content_01” -GradualDelete -Force -Confirm:$false
- Remove-Item “c:\HR_TempSC.bak”
For farther information about Windows PowerShell for SharePoint 2010, you can visit: Windows PowerShell for SharePoint Foundation 2010 reference
I Hope this useful for you,
Thanks.