Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Copy-PnPFile : The remote server returned an error: (500) Internal Server Error. #2780

@gpdhillon

Description

@gpdhillon

I'm trying to copy files from document library to other on SharePoint Online using Copy-PnPFile. All the files are getting copied except for .json file. For JSON file throws "Copy-PnPFile : The remote server returned an error: (500) Internal Server Error."

Steps to reproduce.

  1. open connection
    #$connProjSite = Connect-PnPOnline -Url https://****dev.sharepoint.com/sites/TestSIte

  2. Get files from the folder
    [Microsoft.SharePoint.Client.Folder]$spFolder = Get-PnPFolder -Url "/sites/TestSIte/Shared Documents/Test" -Includes Files -Connection $connProjSite -ErrorAction Continue

  3. Loop thru to copy files
    $spFolder.Files | ForEach-Object {
    [Microsoft.SharePoint.Client.File]$spFile = $_

    Write-Verbose -Verbose -Message "Moving file $($spFile.Name) to $($clientSiteRelativeURL)/$($projectLegalFolderPath)"
    Copy-PnPFile -SourceUrl $spFile.ServerRelativeUrl -TargetUrl "/sites/TestSite/Shared Documents/Test2/$($spFile.Name)" -Connection $connProjSite -OverwriteIfAlreadyExists -Force
    }

This works fine on most documents, but gives the following error on JSON files.

Copy-PnPFile : The remote server returned an error: (500) Internal Server Error.
At C:\Development\SiteProvisioning\PowerShell\JSON Test.ps1:9 char:5

  • Copy-PnPFile -SourceUrl $spFile.ServerRelativeUrl -TargetUrl "/si ...
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : WriteError: (:) [Copy-PnPFile], WebException
    • FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Files.CopyFile

Which version of the PnP-PowerShell Cmdlets are you using?

  • PnP PowerShell for SharePoint 2013
  • PnP PowerShell for SharePoint 2016
  • PnP PowerShell for SharePoint 2019
  • [x ] PnP PowerShell for SharePoint Online

What is the version of the Cmdlet module you are running?

3.22

How did you install the PnP-PowerShell Cmdlets?

  • MSI Installed downloaded from GitHub
  • [x ] Installed through the PowerShell Gallery with Install-Module
  • Other means

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions