We need to move documents from sub site libraries to the main site main document library. We'd like to retain version history.

What is the best way to do this?


There are couple of methods you can try which retain the versions history when moveing the files from one library to other.

  • PowerShell Export Import Method
  • Content and structure
  • Save Site/List as template
  • Migration tool

Read more the above methods here: Move Document Library in SharePoint with metadata

All of the above methods have its own pros and cons but you can try 2nd or 3rd with less efforts.


We can do it by many ways :

Using the list template approach

Save the sub site list template with content, then create the list using that template in the main site.

Using the third-party migration tool

You can use any of the third-party migration tools like ShareGate, Metalogix etc.

Using the PowerShell script

Using the PowerShell script also we can move the document from sub site document library to root site library.

Using the workflow and send to data connection also we can move the document.


1.Save the library as a template.

SharePoint Online: Save List as Template Missing?

Manage list templates

2.Use ShareGate: https://sharegate.com/

3.Use PnP PowerShell to copy all files and folders between document libraries with metadata.

#Function to copy all Items from one library to another
Function Copy-AllDocuments($SourceLibraryName, $TargetLibraryName)
  #Get Source and Target Libraries
  $SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Includes RootFolder
  $TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Includes RootFolder

  #Copy All Files and Folders from Source to Target Library
  Copy-PnPFile -SourceUrl $SourceLibrary.RootFolder.ServerRelativeUrl -TargetUrl 
  $TargetLibrary.RootFolder.ServerRelativeUrl -OverwriteIfAlreadyExists -Force - 

  #Get All Items from Source Library
  $SourceItems = Get-PnPListItem -List $SourceLibraryName
  $TargetItems = Get-PnPListItem -List $TargetLibraryName

  #Get All Items in the Source Library
  ForEach($SourceItem in $SourceItems)
     #Get Metadata from Source Items
     $Metadata = @{
    'Title' = $SourceItem.FieldValues.Title
    'Created'= $SourceItem.FieldValues.Created.DateTime
    'Modified' = $SourceItem.FieldValues.Modified.DateTime
    'Author' = $SourceItem.FieldValues.Author.Email
    'Editor' = $SourceItem.FieldValues.Editor.Email
    #Update Metadata in Target Items
    ForEach($TargetItem in $TargetItems)
    If($SourceItem.FieldValues.FileLeafRef -eq 
        Set-PnPListItem -List $TargetLibrary -Identity $TargetItem.Id -Values 
        $Metadata | Out-Null

#Connect to PnP Online
$SiteURL = "your site collection URL"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Call the function to copy all files between document libraries
Copy-AllDocuments "document library A name" "document library B name"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.