How to export and import or Save SharePoint List/Library template with data using powershell from one web application to another web application
3 Answers
http://technet.microsoft.com/en-gb/library/ee428293(v=office.14).aspx#section1
To export a site, list or document library by using Windows PowerShell
1.Verify that you meet the following minimum requirements: See Add-SPShellAdmin.
2.On the Start menu, click All Programs.
3.Click Microsoft SharePoint 2010 Products.
4.Click SharePoint 2010 Management Shell.
5.At the Windows PowerShell command prompt, type the following command:
Export-SPWeb -Identity <Site URL> -Path <Path and file name> [-ItemUrl <URL of site, list, or library>] [-IncludeUserSecurity] [-IncludeVersions] [-NoFileCompression] [-GradualDelete] [-Verbose]
If the , , or contain any spaces, you must surround these in double quotes (“ ”) or the Windows PowerShell command will return errors.
to import do:
http://technet.microsoft.com/en-us/library/ee428322(v=office.15).aspx
Import-SPWeb -Identity <SiteURL> -Path <ImportFileName> [-Force] [-NoFileCompression] [-Verbose]
Where:
◦ is the URL for the site that you are importing to.
◦ is the name of the file that you are exporting from.
the path is the saved file you generate from the exprot method. When using the method as an example:
Export-SPWeb -Identity http://sitetest:12345/subsite -Path C:\backup\backup.cmp
-ItemUrl /Lists/saveThisList
above im exporting from site 'http://sitetest:12345/subsite' and saving to a folder in 'c' drive 'backup' with the name and extention of 'backup.cmp' and you give the list url of the list item, in my case its under subdirectory 'lists' and called 'saveThisList' (http://sitetest:12345/subsite/Lists/saveThisList)
for import its simply giving the url you want to place it on (site) and the location of the stored backup item on your file system:
Import-SPWeb -Identity http://sitehome:122213/subsite -Path C:\backup\backup.cmp
-Force
You can use following powershell commands to import/export list:
1: #This is the source web that is hosting the lists to move
2: $sourceWebUrl = "http://server.SharePoint.Com/Sub1"
3:
4: #This is the destination web, where the lists will be copied to
5: $destWebUrl = "http://server.SharePoint.com/Sub1/forums"
6:
7: #Location to store the export file
8: $path = "\\Server\Share\"
9:
10: #comma delimited list of List Names to copy
11: $lists = @("List Number 1", "List Number 2")
12:
13:
14: #Loop through the lists, export the list from the source, and import the list into the destination
15: foreach($list in $lists)
16: {
17: "Exporting " + $sourceWebUrl + "/lists/" + $list
18:
19: export-spweb $sourceWebUrl -ItemUrl ("lists/" + $list) -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
20:
21: "Exporting complete."
22:
23:
24:
25: "Importing " + $destWebUrl + "/lists/" + $list
26:
27: import-spweb $destWebUrl -IncludeUserSecurity -path ($path + $list + ".cmp") -nologfile
28:
29: "Importing Complete"
30: "`r`n`r`n"
31: }
-
got below link which working perfect on powershell sharepointnomad.wordpress.com/2012/05/03/…user3760253– user37602532014-07-14 11:02:09 +00:00Commented Jul 14, 2014 at 11:02
See below link for a perfect PowerShell answer on Andre Galitsky's wordpress blog "The SharePoint Nomad" :- http://sharepointnomad.wordpress.com/2012/05/03/how-to-export-and-import-lists-and-libraries-from-a-sharepoint-2010-site-using-powershell/
Heading Script #1: Export all lists and libraries from the source site.
add-pssnapin microsoft.sharepoint.powershell
# Specify the site URL to export
$web = Get-SPWeb "http://sharepointURL/sites/site1/web1"
# Specify output folder to store exported lists
$path = "c:\admin\export\"
foreach($list in $web.lists)
{
"Exporting " + $list.RootFolder.URL
export-spweb $web.URL -ItemUrl $list.RootFolder.URL -IncludeUserSecurity -IncludeVersions All -path ($path + $list + ".cmp") -nologfile
}
Script #2: Import CMP files into the destination site
add-pssnapin microsoft.sharepoint.powershell
# Specify target SharePoint site to import into
$site = "http://sharepoint/sites/test1"
# Specify folder containing exported lists
$folder = "C:\Admin\Import\"
$Files = Get-ChildItem $folder
foreach ($file in $files)
{
$name = $file.Name
"Importing: " + "$folder$name"
import-spweb $site -path ("$folder$name") -includeusersecurity -nologfile
}
-
The difference with this answer for exporting lists is that that the reference to the lists to be exported is loaded from the spweb object from Get-SPWeb. This is the solution for when using Export-SPWeb fails to export a list, for example throwing the error message
Export-SPWeb : The URL provided is invalid. Only valid URLs that are site collections or sites are allowed to be exported using stsadm.exe.Underverse– Underverse2016-05-13 07:52:52 +00:00Commented May 13, 2016 at 7:52