Requirement is to copy and paste all SharePoint lists and libraries from one site to another. While "Save List as a Template" is one approach, it doesn't work for larger lists and its time consuming. Using Central Administration export method also kills my time.
We can copy and paste SharePoint lists using PowerShell. Here is how to Export-Import all lists and libraries from one site to another using PowerShell:
Here is my PowerShell script to copy-pasts all lists and libraries between Sites:
Related Post: Copy SharePoint List or Library between Sites with PowerShell
We can copy and paste SharePoint lists using PowerShell. Here is how to Export-Import all lists and libraries from one site to another using PowerShell:
Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinueThis script helped me to move all lists from a highly customized and corrupted site to a clean SharePoint site.
#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Export-AllLists($WebURL, $ExportPath)
{
#Get the source web
$web = Get-SPWeb $WebURL
#Check the Local Folder export Lists
#Get all lists - Exclude System lists
$ListCollection = $web.lists | Where-Object { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.Author.LoginName -ne "SHAREPOINT\system") }
#Iterate through each list and export
foreach($list in $ListCollection)
{
Write-host "Exporting: " $list.Title
#Remove : from List title - As we can't name a file with : symbol
$ListTitle = $list.Title.Replace(":","")
Export-SPWeb $WebURL -ItemUrl "/$($list.RootFolder.Url)" -IncludeUserSecurity -IncludeVersions All -path ($ExportPath + $ListTitle+ ".cmp") -nologfile
}
}
#Custom PowerShell Function to Export All Lists and Libraries from a SharePoint site
Function Import-AllLists($WebURL, $ImportPath)
{
#Get the Target web
$web = Get-SPWeb $WebURL
#Check the Local Folder export Lists
#Get all File Backups to Import
$FilesCollection = Get-ChildItem $ImportPath
#Iterate through each file and import
foreach($File in $FilesCollection)
{
Write-host "Importing: " $File.Name
Import-SPWeb $webURL -path $ImportPath$File -includeusersecurity -UpdateVersions Overwrite -nologfile
}
}
#Call the function to export
Export-AllLists "http://sales.crescent.com/" "D:\Backup\"
#To import, Use:
#Import-AllLists "http://marketing.crescent.com/" "D:\Backup\"
Here is my PowerShell script to copy-pasts all lists and libraries between Sites:
Related Post: Copy SharePoint List or Library between Sites with PowerShell