Copy Content Of a Folder to Another SP Online Folder

Hamid Sadeghpour Saleh 1 Reputation point MVP
2020-07-14T10:17:05.507+00:00

Hello Experts,

I'm facing an issue while I want to copy just contents of a folder in "Documents" of a site to another SP Online environment site to a folder, and i want to achieve this with a Powershell script. I've created a list and an item which represents destination and source folder and links and I'm using Sharegate Powershell module commands to write the scripts however it's also possible to use without sharegate.

Any solutions?

Thanks in advance.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,652 questions
{count} votes

3 answers

Sort by: Newest
  1. Arijit_cloud 1 Reputation point Microsoft Employee
    2021-03-16T03:00:03.72+00:00

    Hi @Hamid Sadeghpour Saleh ,

    Interesting to see copypnpfile has a restriction on same tenant in the documentation,
    "This location can be within the same document library, same site, same site collection or even to another site collection on the same tenant"

    Since you want to copy between two different tenant, so choices are any of the migration tool OR

    by downloading content to local temp folder and then uploading to the destination.
    For downloading files, you can use getpnpfile

    Get-PnPFile -Url $File.ServerRelativeUrl -Path $LocalDriveFolderPath -FileName $File.Name -AsFile    
    

    While for uploading, you can use addpnpfile

    Add-PnPFile -Path sample.docx -Folder "Documents" -NewFileName "differentname.docx"  
    
    0 comments No comments

  2. Priyanka Singh 1 Reputation point
    2020-09-25T13:32:39.55+00:00

    you can try and use Sharegate for the same if its helpful.
    Thanks

    0 comments No comments

  3. Jerry Xu 256 Reputation points
    2020-07-15T06:15:33.853+00:00

    You can use Copy-PnpFile to do so. It 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. Currently there is a 200MB file size limit for the file or folder to be copied.

    If you have not tried Pnp before, remember to install the module first.

    Here is a demo works in my end.

    #Copy File to Another Site  
    $sourceSiteURL="SourceSiteURL"  
    $UserName="Account"  
    $Password = "PWD"  
    $SourceURL="Shared Documents/folder"  
    $TargetURL="/sites/<siteName>/Shared Documents"  
       
    $SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force  
    $Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword  
       
    #Connect to PNP Online  
    Connect-PnPOnline -Url $sourceSiteURL -Credentials $Cred  
    Copy-PnPFile -SourceUrl $SourceURL -TargetUrl $TargetURL -OverwriteIfAlreadyExists