During an upgrade and reorganization, we had a customer with a requirement to move a Site Collection to be a subsite of another Site Collection. Thankfully, with the new PowerShell capabilities with SharePoint 2010, this task was rather simple.
High-Level Steps
- Export the Site Collection
- Create the New Subsite
- Import the Exported Site Collection
- Delete the Old Site Collection
We have a Site Collection at /sites/MoveMe with a subsite under it at /sites/MoveMe/MoveMe2. We want to relocate this Site Collection under an existing Site Collection at /sites/NewHome.
Follow the steps below to move the site. All of the actions are performed using the SharePoint 2010 Management Shell.
Export the Site Collection
Execute the following command, substituting in the proper Identity parameter for your environment:
Export-SPWeb -Identity https://portal.contoso.com/sites/MoveMe -Path "C:\MoveMe.bak" -IncludeUserSecurity -Compression 1024 -IncludeVersions 4
Note the additional parameters of IncludeUserSecurity, Compression, and IncludeVersions. IncludeUserSecurity is pretty self-explanatory, but Compression will make sure to limit the number of multiple backup files for larger Site Collections, while IncludeVersions 4 says to include all versions for files.
Create a New Subsite
The import command requires that a site exist prior to importing. Therefore, we need to make an empty subsite for our soon-to-be relocated site:
New-SPWeb -URL https://portal.contoso.com/sites/NewHome/MoveMe
Import the Exported Site Collection
Now that we have our exported Site Collection and our empty subsite, we can run the import command to relocate our site:
Import-SPWeb -Identity https://portal.contoso.com/sites/NewHome/MoveMe -Path "C:\MoveMe.bak" -IncludeUserSecurity
Once completed, we can navigate to /sites/NewHome/MoveMe and see that the site now exists in the new location as a subsite. If we navigate to MoveMe2 and use the folder icon, we can confirm that it is now a subsite under MoveMe, which is now a subsite under NewHome:
Delete the Old Site Collection
To clean everything up, we need to delete the old site collection. We perform this step last just in case we experience issues with the middle steps and need to start over:
Remove-SPSite -Identity https://portal.contoso.com/sites/MoveMe
(then Y to Confirm, or include the -Confirm parameter to auto-confirm)
Pingback: Move a Site Collection to a Subsite in SharePoint 2010 « SP2010 Blog
Adam, thanks for the article. Does the Export/Import moves the content database as well? I have site collection to move to the root. The site collection are used by customers right now. Shall i detach the content database and attach it to new site collection? Which approach is best suited?
great article and its clear that how to import and export site collection of sharepoint Thanks
Hi,
good description of the Export and Import Commandlets.
But are you sure, you mean “Moving a Site-COLLECTION” under another site?
As far as I know, a SiteCollection can only be the top of other SiteCollections??
thomas
Great question, but when I say moving I mean demoting a Site Collection to be a subsite under another Site Collection
Hi,
ok, I see, thanks.
BTW, did you try: What happens to the subsites of the source-SiteCollection, if the SiteCollection is being re-imported under another Site??
The subsite moves with it. I confirmed this in the post with the “MoveMe2″ site.
We have a 2007 WSS (SBS 2008) Site Collection to be moved – I see it is easier under 2010, what can I do if anythnig?
Thanks.
Hi everyone,
Let me start with saying, great post. I have a different problem though. I am exporting a subsite using the central admin granular backup. Then importing that web using powershell and everything works like a charm. The only problem is that the list ID’s are not retained in import-export like they are in backup-restore of a site collection. Can anyone please help me with how to retain these ID’s.
Thanks in advance for your help.
Limitations of Import-spweb: http://www.sharepointjoel.com/Lists/Posts/Post.aspx?List=0cd1a63d-183c-4fc2-8320-ba5369008acb&ID=405
(There are a lot!)
Use backup-spsite if you want to retain site collection data, but you cant consolidate. Look into 3rd party products, or scripted solutions that solve the import-spweb limitations.
What about if you want to do the reverse? You have a subsite that you want to promote to a site collection.
What if the source and destination are on different servers (may be of not same version too). Is there any way to do it?
Just to clarify, when you say servers I’m assuming you mean farms.
Not different SP versions: You can still use Export-SPWeb and Import-SPWeb, just move the export file(s) to the other farm prior to running the Import-SPWeb on that farm. Be aware that this includes security so we are assuming both farms are in the same domain.
Different SP Versions: I would isolate the Site Collection to its on Content Database then use the database migration method – which mean moving the DB to the other farm and running upgrade tests on that database (Test-SPContentDatabase). Once the Site Collection is on the destination farm, then use the same steps in this post. Be aware that if you are going down in versions that the database may errorer out due to features not available on the destination farm.
Hi Adam.
Can I export a site without the subsites? I want to create a copy of a site collection, but just a partial copy (only some subsites), so if I can export just a single site I can build my new site collection peace by peace.
Thx