I'm currently looking for a sneaky solution to move documents between SIte Collections. I already found a quite good looking PnP Powershell:

Connect-PnPOnline -Url https://intranet.customer.com/websites/SITECOLL1
Get-PnPFeature -Scope Site
$allDocs = (Get-PnPListItem -List Checklisten).FieldValues
$targetLib = "https://intranet.customer.com/sites/SITECOLL2/Checklisten"
foreach ($item in $allDocs){
Move-PnPFile -ServerRelativeUrl $item.FileRef -TargetUrl ($targetLib + $item.FileLeafRef) -Force

But unfortunately I get for every document an error message like this:

Move-PnPFile : SiteId mismatch In C:\Temp\Powershell\2019\MoveDocuments.ps1:9 Zeichen:5 + Move-PnPFile -ServerRelativeUrl $item.FileRef -TargetUrl ($target ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Move-PnPFile], ServerException + FullyQualifiedErrorId EXCEPTION,SharePointPnP.PowerShell.Commands.Files.MoveFile

We migrated from SharePoint 2013 via detach/attach to SharePoint 2019. Now it's time to switch over to modern UI without those expensive migration tools.

Any thougths/ideas out there what I'm missing or maybe another way to achieve the goal?


1 Answer 1


Try the script below with copy and remove way to do this. I changed a bit from your script. It works in my end properly.

Connect-PnPOnline -Url siteURL
Get-PnPFeature -Scope Site
$allDocs = (Get-PnPListItem -List Documents).FieldValues
$targetLib = "/sites/test/Library"
foreach ($item in $allDocs){
Copy-PnPFile -SourceUrl $item.FileRef -TargetUrl $targetLib -Force -ErrorAction Stop
Remove-PNPFile -ServerRelativeUrl $item.FileRef -Force
  • This did the trick for me. Thank you!
    – airliner
    Oct 21, 2019 at 7:54

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.