Home > other >  Copy-PnPFile returns 401
Copy-PnPFile returns 401

Time:01-22

I am traying to copy files betwen SP Document Librarys, with PnP PowerShell command "Copy-PnPFile",

but I get "Copy-PnPFile : The remote server returned an error: (401) Unauthorized"

In the script before this comand I am reading, items, creating folder and it works, only Copy-PnPFile dont work.

Copy-PnPFile -SourceUrl $Item["FileRef"] -TargetUrl $TargetFileUrl

CodePudding user response:

Make sure $Item["FileRef"] is a relative path. Of course $TargetFileUrl should also be a relative path.


Microsoft Official:

Copy-PnPFile: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. Notice that if copying between sites or to a subsite you cannot specify a target filename, only a folder name.


Here is a nice article for your reference:

CodePudding user response:

My mistake. In source and target relative path forgot to include "SiteCollectionURL".

  •  Tags:  
  • Related