I'm using the below script to copy the files from source library to destination library. Script run successfully but after certain period i am getting the below error.

I've close to 20000 items in source library to copy. Can one help on how to resolve this issue?

Error: Copy-PnPFile : The underlying connection was closed: An unexpected error occurred on a receive/send.

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
$SiteURL = "your site collection URL"
$SourceFolderURL = "/sites/site collection name/document library name"
$TargetFolderURL = "/sites/site collection name/document library name"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
#Copy All Files and Folders between source and target folders
Copy-PnPFile -SourceUrl $SourceFolderURL -TargetUrl $TargetFolderURL -SkipSourceFolderName -Force -OverwriteIfAlreadyExists

1 Answer 1


Quoting to the document: Copy-PnPFile

Currently there is a 200MB file size limit for the file or folder to be copied.

I have tested with the Copy-PnPFile command and it works fine. I suppose you do not have the same issue if you run the script in a smaller library.

Try moving the documents in the source document library into multiple folders and then run the script on one of the folders again. See if you will reproduce this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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