Copy SharePoint List or Library between Sites with PowerShell

In a migration project, we had to move a few lists and libraries to a different site collection. In SharePoint 2010, using granular export, we can export SharePoint lists and libraries from one site to another with the SharePoint Central Administration web interface.
copy sharepoint 2010 list between sites
Once exported we’ve to use Import-SPWeb PowerShell cmdlet to restore the list. Lists can be copied to different SharePoint sites as well.
copy sharepoint list another site
Exporting from Central Admin UI and importing it again isn’t that great time-saver, So let’s turn our attention to PowerShell to copy SharePoint 2010 list between sites. Here is my PowerShell script to copy a single List or Library to another SharePoint Site:

Export-Import a Library using PowerShell:

Export-SPWeb "http://your-site-url" -itemurl "/document" -path "c:\documents.cmp" -IncludeVersions All

Import-SPWeb "http://your-new-site-url/" -Path "c:\documents.cmp"

PowerShell Script to Backup-Restore (Or Export-Import) SharePoint List:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to copy List or Library from One SharePoint site to another 
Function CopyList([string]$SourceWebURL, [string]$TargetWebURL, [string]$ListName, [string]$BackupPath)
 {
    #Get the Source List
    $SourceList =(Get-SPWeb $SourceWebURL).Lists[$ListName]

    #Export the List from Source web
    Export-SPweb $SourceWebURL -ItemUrl $SourceList.DefaultViewUrl -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + $ListName + ".cmp") -nologfile

   #Import the List to Target Web
    import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + $ListName + ".cmp") -nologfile
 }
#Call the function
CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/teams/marketing" "Banner" "C:\Temp\"

When I had a bunch of Lists to move from one site to another, I Just placed them in an array and called the function like this:

$Lists = @("Project Docs", "Project Metrics", "Milestones")

 foreach($List in $Lists)
 {
   #Call the function to copy
   CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/teams/marketing" $List "C:\Temp\"
 }
 
 Write-Host "Completed!"

In an another situation, I had to copy of all Lists and libraries from a one Site Collection to another Site Collection. To export a single list use:

Export-SPweb "https://portal.crescent.com/News" -ItemUrl "Lists/Org News" -IncludeUserSecurity -IncludeVersions All -path "C:\Reports\News.cmp" -nologfile

PowerShell Script to Copy All Lists from One Site to Another

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Function to copy List or Library from One SharePoint site to another 
Function CopyList([string]$SourceWebURL, [string]$TargetWebURL, [string]$ListName, [string]$BackupPath)
{
    #Get the Source List
 $SourceList =(Get-SPWeb $SourceWebURL).Lists[$ListName]

   #Export the List from Source web
    Export-SPweb $SourceWebURL -ItemUrl $SourceList.DefaultViewUrl -IncludeUserSecurity -IncludeVersions All -path ($BackupPath + $ListName + ".cmp") -nologfile -Force

   #Import the List to Target Web
    import-spweb $TargetWebURL -IncludeUserSecurity -path ($BackupPath + $ListName + ".cmp") -nologfile -UpdateVersions Overwrite
}
  
#Get All List Names
$Lists = @($(Get-SPWeb $SourceWebURL).lists)

foreach($List in $Lists)
{
    #Leave the Hidden Lists and exclude certain Libraries
    if($List.Hidden -eq $false -and $List.Title -ne "Style Library" -and $List.Title -ne "Site Pages")
    {
      #Call the function to copy
      CopyList "http://sharepoint.crescent.com" "http://sharepoint.crescent.com/HR/" $List.Title "C:\Temp\"
    }
}
Write-Host "Completed Copying Lists!"

These scripts copies SharePoint list to another site including security and versions. Saving list as template with content, Export to spreadsheet are the OOTB methods for copying lists between site collections.

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

5 thoughts on “Copy SharePoint List or Library between Sites with PowerShell

  • September 11, 2019 at 2:31 AM

    Thanks for this script ! Can we apply this to copy multiple lists from SharePoint 2016 to Online ?

    Reply
  • July 26, 2016 at 3:50 PM

    Great Script – thanks a lot!

    Reply
  • October 30, 2013 at 2:35 PM

    Nice article. FYI -The initial CopyList function script has the export command commented out.

    Reply

Leave a Reply