
Use below PnP PowerShell to copy all files and folders between Document Libraries with Metadata to check if it works:
#Function to copy all Items from one library to another
Function Copy-AllDocuments($SourceLibraryName, $TargetLibraryName)
{
#Get Source and Target Libraries
$SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Includes RootFolder
$TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Includes RootFolder
#Copy All Files and Folders from Source to Target Library
Copy-PnPFile -SourceUrl $SourceLibrary.RootFolder.ServerRelativeUrl -TargetUrl $TargetLibrary.RootFolder.ServerRelativeUrl -OverwriteIfAlreadyExists -Force -SkipSourceFolderName
#Get All Items from Source Library
$SourceItems = Get-PnPListItem -List $SourceLibraryName
$TargetItems = Get-PnPListItem -List $TargetLibraryName
#Get All Items in the Source Library
ForEach($SourceItem in $SourceItems)
{
#Get Metadata from Source Items
$Metadata = @{
'Title' = $SourceItem.FieldValues.Title
'Created'= $SourceItem.FieldValues.Created.DateTime
'Modified' = $SourceItem.FieldValues.Modified.DateTime
'Author' = $SourceItem.FieldValues.Author.Email
'Editor' = $SourceItem.FieldValues.Editor.Email
}
#Update Metadata in Target Items
ForEach($TargetItem in $TargetItems)
{
If($SourceItem.FieldValues.FileLeafRef -eq $TargetItem.FieldValues.FileLeafRef)
{
Set-PnPListItem -List $TargetLibrary -Identity $TargetItem.Id -Values $Metadata | Out-Null
}
}
}
}
#Connect to PnP Online
$SiteURL = "https://crescent.sharepoint.com/sites/marketing/"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Call the function to copy all files between document libraries
Copy-AllDocuments "Project Documents" "Temp"
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.