Export-Import All Lists and Libraries from One Site to Another using PowerShell

The 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 is time-consuming. Using the Central Administration export method also kills my time.

export import sharepoint list using powershell

Solution: We can copy and paste SharePoint lists using the PowerShell script.

Export document library using PowerShell in SharePoint 2013 / 2016:

Export-SPWeb <Web-URL> -Path <Backup-Path> -ItemURL <Library-URL> -IncludeUserSecurity  -IncludeVersions All


Export-SPWeb https://sharepoint.crescent.com/Teams/2015-ESG/ -Path "D:\Documents.cmp" -ItemURL "Documents" -IncludeUserSecurity -IncludeVersions All 

Import document library in SharePoint 2013 using PowerShell:

Import-SPWeb <<web-URL>> -path <<Backup-file>> -force -IncludeUserSecurity -UpdateVersions Overwrite


Import-SPWeb https://sharepoint.crescent.com/Teams/2016-ESG/" -Path "D:\Documents.cmp" -force -IncludeUserSecurity -UpdateVersions Overwrite

Export-Import all lists and libraries from one site to another site using PowerShell:

Use this PowerShell script to export all lists from a site.

Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue

#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(":",[string]::Empty)
        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 "https://sales.crescent.com/" "D:\Backup\"
#To import, Use:
#Import-AllLists "https://marketing.crescent.com/" "D:\Backup\"

This script helped me to move all lists from a highly customized and corrupted site to a clean SharePoint site. Here is another PowerShell script to copy-paste all lists and libraries between Sites: Copy SharePoint List or Library between Sites with PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “Export-Import All Lists and Libraries from One Site to Another using PowerShell

  • Hi Salaudeen Rajack

    Will this ONLY work as export from SP 2010 and then import to SP 2010
    or will it also work importing into newer SP version, as e.g. 2019 or SE version (all On-prem)
    (I know that Backup-SPSite/Restore-SPSite fails miserably in that sense, as a sort of “migration tool”)

    Regards, Brian

  • Hello Salaudeen Rajack!

    I am having a problem importing site in to site collection with this command.
    Import-SPWeb -Identity “https://mytestSite/Access” -Path “F:\Access.cmp” -Force -IncludeUserSecurity -NoFileCompression -Confirm:$false
    Import-SPWeb : Updates to system roles is not allowed.
    [FatalError] [-2146233079] [System.InvalidOperationException] [Updates to system roles is not allowed.]
    [12/14/2023 7:38:17 PM] [Debug] at Microsoft.SharePoint.Deployment.RolesImport.ProcessSimpleElement(ImportStreamingContext context, XmlReader xr, SqlSession session, SqlCommand comm, Int32 iRow)
    at Microsoft.SharePoint.Deployment.SqlBatchImport.Run()

    Someone suggested to export it with this command
    Export-SPWeb -Identity “https://mytestSite/Access” -Path “F:\Access.cmp” -Force -IncludeUserSecurity -NoFileCompression -ExcludeGroups “System Account”, “Everyone”, “Authenticated Users”

    But I could not find “ExcludeGroups” in the list of exceptable parameters. Can you comment on it or have a better solution? Thanks

  • Tried above powersheel but getting error as “Export-SPWeb : The URL provided is invalid. Only valid URLs that are site collections or sites are allowed to be exported using stsadm.exe.”


Leave a Reply

Your email address will not be published. Required fields are marked *