Migration can be achieved in four different ways.
- Using Power shell Script.
- Using Third Party Tool like Sharegate
- Using List Template.
- Microsoft Access 2013.
In this blog, we will discuss only using power shell script.
- Open window powershell in source machine.
- Before running export command please change the WebURL to Source Site URL, ListName is the list which we need to migrate and provide the physical path to save the export file. Export-List -WebUrl "http://yoursite:portnumber/" -ListName"ExistingDemo" -Path "D:\ExistingDemoExport" -Overwrite
- Run the export command in powershell window. When export command is successful following file will find in physical location.
- Open the file into notepad. i.e. SystemData.xml
- Change the version and build attributes value in SystemData.xml file according to the new environment.
- To change the build attribute value open Central Administration on destination site and navigate to Upgrade and Migration->Check product and patch installation status. Copy the highlighted text and replace the build attribute value in SystemData.xml file.
- Version attribute value will be:
Sharepoint 2010 : Version="14.0.0.0"
Sharepoint 2013 : Version="15.0.0.0"
- After replacing build and attribute value as per above description. Save the SystemData.xml file at same location.
- Open Window Powershell at destination site and run the export command after amending below line in Import command.
Import-List -WebUrl “http://intranet/sites/sales” -Path ""D:\ExistingDemoExport""
Using Power Shell Script
Export Command
- function Export - List {
- Param(
- [parameter(Mandatory = $true)][string] $WebUrl,
- [parameter(Mandatory = $true)][string] $ListName,
- [parameter(Mandatory = $true)][string] $Path,
- [parameter(Mandatory = $false)][
- switch
- ] $ExcludeDependencies,
- [parameter(Mandatory = $false)][
- switch
- ] $HaltOnWarning,
- [parameter(Mandatory = $false)][
- switch
- ] $HaltOnNonfatalError,
- [parameter(Mandatory = $false)][
- switch
- ] $AutoGenerateDataFileName,
- [parameter(Mandatory = $false)][
- switch
- ] $TestRun,
- [parameter(Mandatory = $false)][string] $IncludeSecurity,
- [parameter(Mandatory = $false)][string] $IncludeVersions,
- [parameter(Mandatory = $false)][int] $FileMaxSize,
- [parameter(Mandatory = $false)][
- switch
- ] $Overwrite,
- [parameter(Mandatory = $false)][
- switch
- ] $SuppressLog)
- #Load SharePoint 2010 cmdlets
- $ver = $host | select version
- if ($ver.Version.Major - gt 1) {
- $Host.Runspace.ThreadOptions = "ReuseThread"
- }
- Add - PsSnapin Microsoft.SharePoint.PowerShell - ErrorAction SilentlyContinue
- #Load assemblies(needed
- for SharePoint Server 2007)[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
- #Check parameters have the correct values
- if (!$IncludeSecurity) {
- $IncludeSecurity = "None"
- } else {
- if (($IncludeSecurity - ne "All")
- `
- -and ($IncludeSecurity -ne "WssOnly") ` - and($IncludeSecurity - ne "None")) {
- Throw "The IncludeSecurity parameter must be set to All, WssOnly or None"
- }
- }
- if (!$IncludeVersions) {
- $IncludeVersions = "LastMajor"
- } else {
- if (($IncludeVersions - ne "All")
- `
- -and ($IncludeVersions -ne "CurrentVersion") ` - and($IncludeVersions - ne "LastMajor")
- `
- -and ($IncludeVersions -ne "LastMajorAndMinor"))
- {
- Throw "The IncludeVersions parameter must be set to All, CurrentVersion, LastMajorAndMinor or LastMajor"
- }
- }
- if (!$FileMaxSize)
- {
- $FileMaxSize = 0
- }
- $site = New-Object Microsoft.SharePoint.SPSite($WebUrl)
- $web = $site.OpenWeb()
- $list = $web.Lists[$ListName]
- [bool]$FileCompression = $false
- #Set file paths for the export file and logs
- [string]$exportPath = $Path.TrimEnd("\")
- if ($exportPath.EndsWith(".cmp"))
- {
- $FileCompression = $true
- $exportFile = $Path.Replace($Path.Remove($Path.LastIndexOf("\")+1),"")
- $exportPath = $Path.Remove($Path.LastIndexOf("\"))
- }
- $logFilePath = $exportPath + "\exportlog.txt"
- New-Item -Path $logFilePath -Type File -Force | Out-Null
- Write-Host "Export log file created at" $logFilePath
- $exportObject = New-Object Microsoft.SharePoint.Deployment.SPExportObject
- $exportObject.Id = $list.ID
- $exportObject.Type = [Microsoft.SharePoint.Deployment.SPDeploymentObjectType]::List
- #Create the export settings from the parameters specified
- $exportSettings = New-Object Microsoft.SharePoint.Deployment.SPExportSettings
- $exportSettings.SiteUrl = $site.Url
- $exportSettings.ExportMethod = [Microsoft.SharePoint.Deployment.SPExportMethodType]::ExportAll
- $exportSettings.FileLocation = $exportPath
- $exportSettings.FileCompression = $FileCompression
- if ($FileCompression) { $exportSettings.BaseFileName = $exportFile }
- $exportSettings.ExcludeDependencies = $ExcludeDependencies
- $exportSettings.OverwriteExistingDataFile = $Overwrite
- $exportSettings.IncludeSecurity = $IncludeSecurity
- $exportSettings.IncludeVersions = $IncludeVersions
- $exportSettings.LogFilePath = $logFilePath
- $exportSettings.HaltOnWarning = $HaltOnWarning
- $exportSettings.HaltOnNonfatalError = $HaltOnNonfatalError
- $exportSettings.AutoGenerateDataFileName = $AutoGenerateDataFileName
- $exportSettings.TestRun = $TestRun
- $exportSettings.FileMaxSize = $FileMaxSize
- $exportSettings.ExportObjects.Add($exportObject)
- #Write the export settings to a log file
- Out-File -FilePath $logFilePath -InputObject $exportSettings -Append -Encoding utf8
- #Run the export procedure
- $export = New-Object Microsoft.SharePoint.Deployment.SPExport($exportSettings)
- $export.Run()
- #Load notepad showing the log file
- if (!$SuppressLog) { notepad $logFilePath }
- #Dispose of the web and site objects after use
- $web.Dispose()
- $site.Dispose()
- }
- Export-List -WebUrl "yoursite" -ListName "listname" -Path "E:\arvind\ForMigration\FromLive\Incident" -Overwrite
Import Command
- function Import - List {
- Param(
- [parameter(Mandatory = $true)][string] $WebUrl,
- [parameter(Mandatory = $true)][string] $Path,
- [parameter(Mandatory = $false)][
- switch
- ] $HaltOnWarning,
- [parameter(Mandatory = $false)][
- switch
- ] $HaltOnNonfatalError,
- [parameter(Mandatory = $false)][
- switch
- ] $RetainObjectIdentity,
- [parameter(Mandatory = $false)][string] $IncludeSecurity,
- [parameter(Mandatory = $false)][string] $UpdateVersions,
- [parameter(Mandatory = $false)][
- switch
- ] $SuppressLog)
- #Load SharePoint 2010 cmdlets
- Add - PSSnapin Microsoft.SharePoint.PowerShell - erroraction SilentlyContinue
- #Load assemblies(needed
- for SharePoint Server 2007)[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
- #Check parameters have the correct values
- if (!$IncludeSecurity) {
- $IncludeSecurity = "None"
- } else {
- if (($IncludeSecurity - ne "All")
- `
- -and ($IncludeSecurity -ne "WssOnly") ` - and($IncludeSecurity - ne "None")) {
- Throw "The IncludeSecurity parameter must be set to All, WssOnly or None"
- }
- }
- if (!$UpdateVersions) {
- $UpdateVersions = "Overwrite"
- } else {
- if (($UpdateVersions - ne "Overwrite")
- `
- -and ($UpdateVersions -ne "Append") ` - and($UpdateVersions - ne "Ignore")) {
- Throw "The UpdateVersions parameter must be set to Overwrite, Append or Ignore"
- }
- }
- $site = New - Object Microsoft.SharePoint.SPSite($WebUrl)
- $web = $site.OpenWeb()
- $importSettings = New - Object Microsoft.SharePoint.Deployment.SPImportSettings
- #Set file paths
- for the
- import file and logs
- $fileName = ""
- if ($Path.EndsWith(".cmp")) {
- $fileName = $Path.Replace($Path.Remove($Path.LastIndexOf("\")+1),"
- ")
- $importPath = $Path.Remove($Path.LastIndexOf("\"))
- $importSettings.FileCompression = $true $importSettings.BaseFileName = $fileName
- }
- else {
- $importPath = $Path.TrimEnd("\")
- $importSettings.FileCompression = $false
- }
- $logFilePath = $importPath + "\importlog.txt"
- New - Item - Path $logFilePath - Type File - Force | Out - Null
- Write - Host "Import log file created at"
- $logFilePath
- #Create the
- import settings from the parameters specified
- Write - Host "Configuring import settings"
- $importSettings.SiteUrl = $site.Url
- $importSettings.WebUrl = $web.Url
- $importSettings.FileLocation = $importPath
- $importSettings.IncludeSecurity = $IncludeSecurity
- $importSettings.UpdateVersions = $UpdateVersions
- $importSettings.LogFilePath = $logFilePath
- $importSettings.HaltOnWarning = $HaltOnWarning
- $importSettings.HaltOnNonfatalError = $HaltOnNonfatalError
- $importSettings.RetainObjectIdentity = $RetainObjectIdentity
- $importSettings.UserInfoDateTime = "ImportAll"
- if (!$SuppressLog) {
- $importSettings
- }
- #Write the
- import settings to a log file
- Out - File - FilePath $logFilePath - InputObject $importSettings - Append - Encoding utf8
- #Run the
- import procedure
- Write - Host "Import running, please wait..."
- $import = New - Object Microsoft.SharePoint.Deployment.SPImport($importSettings)
- $import.Run()
- Write - Host "Import from"
- $Path "complete"
- #Load notepad showing the log file
- if (!$SuppressLog) {
- notepad $logFilePath
- }
- #Dispose of the web and site objects after use
- $web.Dispose()
- $site.Dispose()
- }
Import-List -WebUrl “http://intranet/sites/sales” -Path "C:\Export\TeamContacts"