Hi @Aran Billen,
Please try this PowerShell script to move folder to another library. Be sure to set the parameters, such as the Site URL and source directory.
#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"
#Function to Move a Folder
Function Move-SPOFolder([String]$SiteURL, [String]$FolderSourceURL, [String]$FolderTargetURL )
{
Try{
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Move the Folder
$MoveCopyOpt = New-Object Microsoft.SharePoint.Client.MoveCopyOptions
#$MoveCopyOpt.KeepBoth = $True
[Microsoft.SharePoint.Client.MoveCopyUtil]::MoveFolder($Ctx, $FolderSourceURL, $FolderTargetURL, $MoveCopyOpt)
$Ctx.ExecuteQuery()
Write-host -f Green "Folder Moved Successfully!"
}
Catch {
write-host -f Red "Error Moving the Folder!" $_.Exception.Message
}
}
#Set Config Parameters
$SiteURL="https://mycompany.sharepoint.com/"
$FolderSourceURL="https://mycompany.sharepoint.com/sites/sitename/SitePages/foldername"
$FolderTargetURL="https://mycompany.sharepoint.com/sites/sitename/libraryname/foldername"
#Get Credentials to connect
$Cred= Get-Credential
#Call the function to Move the Folder
Move-SPOFolder $SiteURL $FolderSourceURL $FolderTargetURL
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.