This article demonstrates exporting and importing a Site using PowerShell. 

This script exports a site, and then prompts you to confirm importing it. If you type "y" it will import the Site, other the script ends. In this way it gives you to chance to analyze the file sizes and other factors before import a site. 

Applies To

  • SharePoint 2010
  • SharePoint 2007


This script can be downloaded from the TechNet Gallery.

PowerShell Script

param([string]$Sourceurl,[string]$Destinationurl, [string]$FileName, [string]$Location, [switch]$help)           
function GetHelp() {           
$HelpText = @"
This script export a site from source site and then imports that at a destination url.
It has a check also before it goes for import.
function RahulExportImport-SPSite([string]$Sourceurl,[string]$Destinationurl, [string]$FileName, [string]$Location) {           
 if(Test-Path $Location) {            
 } else {           
  new-item -path $Location -type directory | Out-Null           
 $SPExport = New-Object Microsoft.SharePoint.Deployment.SPExport           
 $SPImport = New-Object Microsoft.SharePoint.Deployment.SPImport           
 $SPExportSettings = $SPExport.Settings           
 $SPExportSettings.SiteUrl= $Sourceurl           
 $SPExportSettings.BaseFilename = $FileName           
 $SPExportSettings.FileLocation = $Location           
 $SPExportSettings.CommandLineVerbose = $true           
 $SPExportSettings.ExportMethod = [Microsoft.SharePoint.Deployment.SPExportMethodType]"ExportAll"           
 $SPExportSettings.LogFilePath =$Location +"\logExport.log"           
 write-host "The export is completed. Do you want to go for Import? If Yes then type y or else type anything else"           
 $Decision = read-host           
 if($Decision -eq "y")           
     $SPImportSettings = $SPImport.Settings           
     $SPImportSettings.SiteUrl= $Destinationurl           
     $SPImportSettings.BaseFilename = $FileName           
     $SPImportSettings.FileLocation = $Location           
     $SPImportSettings.CommandLineVerbose = $true           
     $SPImportSettings.LogFilePath =$Location +"\logImport.log"           
if($help) { GetHelp; Continue }           
if($Sourceurl -AND $Destinationurl -AND $FileName -AND $Location)           
    RahulExportImport-SPSite -Sourceurl $Sourceurl -Destinationurl $Destinationurl -FileName $FileName -Location $Location            

See Also

Other languages

This article is also available in the following languages :