This script will move a SharePoint 2010 sub site to a new location on the same farm using the export and import commands. Firstly, set the variables required by the script, these include export folder, export file, export site and import location. Then the script will get the site template used by the exported site as this is required when creating the empty site ready for the import. The script then creates a folder for the export and import files, exports the specified site, creates the empty placeholder site in the specified location and finally imports the exported site into the specified location.
 
 
 
PowerShell
Edit|Remove
# add SharePoint snapin 
Add-PSSnapin Microsoft.SharePoint.PowerShell –ea SilentlyContinue 
 
# set variables 
$exportfolder = "C:\Site exports" 
$exportfile = "\site_export.cmp" 
$exportsite = "http://vm353/PWA/PAULMATHERTESTSITE" 
$exportlocation = $exportfolder+$exportfile 
$importlocation = "http://vm353/PAULMATHERTESTSITE" 
 
#get export site's template 
$web = Get-SPWeb $exportsite 
$webTemp =  $web.WebTemplate 
$webTempID = $web.Configuration 
$webTemplate = "$webTemp#$webTempID" 
$web.Dispose() 
 
#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" 
 For an example walkthrough using this script please see the following blog post: