SharePoint Online - Move folders between sites

Wesley 0 Reputation points
2023-03-06T18:47:32.31+00:00

A sector of the company has spread into smaller parts and I need to migrate the data to the correct sites, however I need to maintain the version history, I managed to create a script to copy the data, but it loses the file history.

User's image

Screenshot_1

It is very important to keep the version history, can someone help me to assemble a script to perform this copy keeping the version history.

As the folder is big, I can't move it using the site's copy/move function, only script works.

Microsoft 365 and Office | SharePoint | For business | Windows
Windows for business | Windows Server | User experience | PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Yanli Jiang - MSFT 31,606 Reputation points Microsoft External Staff
    2023-03-07T09:15:20.1366667+00:00

    Hi @Wesley ,

    You can use Copy-PnPFile cmd.

    SYNTAX

    Copy-PnPFile [-SourceUrl] <String> [-TargetUrl] <String> [-Overwrite] [-Force] [-IgnoreVersionHistory] [-NoWait] [-Connection <PnPConnection>]  
      [<CommonParameters>]
    

    DESCRIPTION

    Copies a file or folder to a different location. This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name. It is currently not possible to copy files between a OneDrive for Business site to SharePoint or vice versa.

    NOTE:

    Moving and copying across sites

    Copying/Moving multiple files in a single operation has three requirements:

    • No more than 100 GB total file size
    • No more than 30,000 files
    • Each file must be less than 15 GB

    For more information, please refer to:

    https://pnp.github.io/powershell/cmdlets/Copy-PnPFile.html


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. Wesley 0 Reputation points
    2023-03-08T12:51:31.3866667+00:00
    Hi,
    
    This script was used to perform the migration of folders:
    
    $SiteURL = "https://*****.sharepoint.com/sites/Administrative"
    $SourceFolderURL= "Serv Files/cost center/"
    $TargetFolderURL = "/sites/Financial/Serv Files"
    
    Connect-PnPOnline -Url $SiteURL -UseWebLogin
    Copy-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -Force
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.