Copy-PnPFile returns 401

Solution 1:

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:

Solution 2:

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