Home > Paul Mather, Work > Move a #SharePoint 2010 sub site to a different location on the same farm #SP2010 #PS2010 #PowerShell

Move a #SharePoint 2010 sub site to a different location on the same farm #SP2010 #PS2010 #PowerShell

Paul Mather
I am a Project Server and SharePoint consultant but my main focus currently is around Project Server.
I have been working with Project Server for nearly five years since 2007 for a Microsoft Gold Certified Partner in the UK, I have also been awared with the Microsoft Community Contributor Award 2011.
I am also a certified Prince2 Practitioner.

This article has been cross posted from pwmather.wordpress.com (original article)

Recently a query came up on the Project Server forums asking how to move a SharePoint site from the PWA site collection to another site collection. Please note this was not a Project Site. For this question I created a simple PowerShell script that will export the site and import it into the specified location. Even though this example is for a site in the PWA site collection, it will work for a site in any SharePoint 2010 site collection providing the same site templates, features etc. are available.

The script is available to download from the Microsoft Script Center:


Below is a walkthrough on using and executing the script.

Firstly download the script and set the variables:

# set variables
$exportfolder = "C:\Site exports"         – Specify the folder to be created, this is where the export files will be created
$exportfile = "\site_export.cmp"        – Specify the export file name
$exportsite = "http://vm353/PWA/PAULMATHERTESTSITE"       – Specify the URL of the site that you want to move
$exportlocation = $exportfolder+$exportfile      – This does not need to be updated
$importlocation = "http://vm353/PAULMATHERTESTSITE"   – Specify the location where you want the site to be imported

The next part of the script gets the exported site’s template as this is needed to create the placeholder site later on:

#get export site’s template
$web = Get-SPWeb $exportsite
$webTemp =  $web.WebTemplate
$webTempID = $web.Configuration
$webTemplate = "$webTemp#$webTempID"

Worthing noting is that you need to use the Configuration property as the template ID rather than the WebTemplateID property as the WebTemplateID will always contain the original ID for the first template Microsoft created. For example a Team Site template ID is STS#0, but the WebTemplateID property for a Team Site will contain a 1, the Configuration property will contain the correct ID, in this case a 0.

The final part of the script is does the export and import, the comments above each line advise what that part of the script is doing.

#create export folder
$null = New-Item $exportfolder -type directory
#export site
Export-SPWeb $exportsite –Path $exportlocation -IncludeUserSecurity -IncludeVersions 4
Write-host "$exportsite has been exported to $exportlocation"
#create new site ready for import
$null = New-SPWeb $importlocation -Template "$webTemplate"
Write-host "$importlocation created ready for import"
#import site
Import-SPWeb $importlocation –Path $exportlocation -IncludeUserSecurity –UpdateVersions 2
Write-host "$exportsite has been imported to $importlocation" -foregroundcolor "Green"

Now lets have a walkthrough and move a site, in the example I have a Team site called “PAULMATHERTESTSITE” that is below the PWA site collection, I want to move this to the top level root site collection. For this example the variables above are correct. Open PowerShell on the Application server and navigate to the location of the ps1 file, in this case it is on my desktop:


Press Enter to execute the script:


A copy of the site should now exist in the new location.

As always, this script is provided as is with no warranties etc. use at your own risk and test on a test environment before using on a production environment.

Categories: Paul Mather, Work Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: