Hi @Hafiz Hussain ,
According to my research and testing, you can try to use the following code to move files between libraries:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#powershell script to move files in sharepoint online - Function
Function Move-SPOFile([String]$SiteURL, [String]$SourceFileURL, [String]$TargetFileURL)
{
Try{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#sharepoint online powershell to move files
$MoveCopyOpt = New-Object Microsoft.SharePoint.Client.MoveCopyOptions
$Overwrite = $True
[Microsoft.SharePoint.Client.MoveCopyUtil]::MoveFile($Ctx, $SourceFileURL, $TargetFileURL, $Overwrite, $MoveCopyOpt)
$Ctx.ExecuteQuery()
Write-host -f Green "File Moved Successfully!"
}
Catch {
write-host -f Red "Error Moving the File!" $_.Exception.Message
}
}
#Set Config Parameters
$SiteURL="https://xxx.sharepoint.com/sites/zellatest"
$SourceFileURL="https://xxxx.sharepoint.com/sites/zellatest/upload/theme.docx"
$TargetFileURL="https://xxxx.sharepoint.com/sites/zellatest/test1/theme.docx"
#Get Credentials to connect
$Cred= Get-Credential
#Call the function to Move the File
Move-SPOFile $SiteURL $SourceFileURL $TargetFileURL
My test result:
More information for reference: SharePoint Online: Move a File between Document Libraries using PowerShell
Hope it can help you. Thanks for your understanding.
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
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.