if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{Add-PSSnapin Microsoft.SharePoint.Powershell}
#$SourceSite = "http://intranet.contoso.com/"
#$ItemURL = "/Lists/Tasks"
#$DestSite = "http://www.cotoso.com/"
$Path = $ENV:HOMEDRIVE + "\"
$Filename = $Path + "export.cmp"
$SourceSite = Read-Host "Enter Source Site URL"
$ItemURL = Read-Host "Enter relative URL of List / Library e.g. /Lists/Tasks or /Shared Documents"
$DestSite = Read-Host "Enter Destination Site URL"
Write-Host "Exporting from Source `t`t: " -NoNewline; Write-Host $SourceSite$ItemURL -ForegroundColor "Magenta"; Write-Host "Importing to Destination `t: " -NoNewline; Write-Host $DestSite$ItemURL -ForegroundColor "Magenta"
Write-Host "The Export file and import / export logs will be available at " -NoNewline; Write-Host $Path -ForegroundColor "Magenta"
Write-Host "Note :"
Write-Host "1) Destination Library will be created if it doesnt exist. If exists then items will be added to it"
Write-Host "2) If the item(s) exists, they will NOT be overwritten, instead a new item will be added"
Export-SPWeb -Identity $SourceSite -Path $Filename -ItemUrl $ItemURL -IncludeUserSecurity -IncludeVersions 4 -Force
Import-SPWeb -Identity $DestSite -Path $Filename -ActivateSolutions -IncludeUserSecurity
Write-Host `t$Filename".export.log"
if ( (Get-PSSnapin-Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {Add-PSSnapin Microsoft.SharePoint.Powershell} #$SourceSite = "http://intranet.contoso.com/"#$ItemURL = "/Lists/Tasks"#$DestSite = "http://www.cotoso.com/"$Path = $ENV:HOMEDRIVE + "\" $Filename = $Path+"export.cmp"$SourceSite = Read-Host"Enter Source Site URL"$ItemURL = Read-Host"Enter relative URL of List / Library e.g. /Lists/Tasks or /Shared Documents"$DestSite = Read-Host"Enter Destination Site URL" Write-Host "Exporting from Source `t`t: "-NoNewline; Write-Host $SourceSite$ItemURL-ForegroundColor "Magenta"; Write-Host "Importing to Destination `t: "-NoNewline; Write-Host $DestSite$ItemURL-ForegroundColor "Magenta" Write-Host "The Export file and import / export logs will be available at "-NoNewline; Write-Host $Path-ForegroundColor "Magenta" Write-Host "Note :" Write-Host "1) Destination Library will be created if it doesnt exist. If exists then items will be added to it" Write-Host "2) If the item(s) exists, they will NOT be overwritten, instead a new item will be added" Export-SPWeb -Identity $SourceSite-Path $Filename-ItemUrl $ItemURL-IncludeUserSecurity -IncludeVersions 4 -Force Import-SPWeb -Identity $DestSite-Path $Filename-ActivateSolutions -IncludeUserSecurity Write-Host `t$Filename".export.log"
Example 2: How to export and import “Shared Documents” library from one web to another web
Execute the script and it will ask for the required details.
