I am writing a powershell script to copy files (documents) from a OneDrive site to a SharePoint site. They are in different site collections.
I am using this command:
Copy-PnPFile -SourceUrl $file.fieldvalues.FileRef -TargetUrl $destpath -OverwriteIfAlreadyExists -Force -ErrorVariable errors -ErrorAction SilentlyContinue
But it is giving me 404 error. I think the error is coming from the
-sourceurl parameter since they are from different site collection. I tried adding the whole url of the source file but it gave me this error:
Copy-PnPFile : Value does not fall within the expected range.
I can just load the files using
$docLibrary = $ctx.Web.Lists.GetByTitle("Documents"), but I'm not sure how to copy its contents to the SharePoint site. Is there any possible approach?
P.S: I am getting the files form the onedrive using
$items = Get-PnPListItem -List Documents -PageSize 1000.