Forum Discussion
SharePoint Online - Copy site pages between site collections - is that possible?
fstorer Hi, for anyone looking for a solution this might help:
Import-Module SharePointPnPPowerShellOnline
#Source and Target Sites
$tenant = "tenant";
$SourceUrl="https://$tenant.sharepoint.com/sites/sourceSite"
$targetRelativeLibraryUrl="/sites/marketing/SitePages"
#SPO Connection
$AdminPassword=Read-Host -Prompt "Password" -AsSecureString
$adminUPN = "admin@australia.com.au"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUPN, $AdminPassword
Connect-PnPOnline -Url $SourceUrl -Credentials $cred
#Connect-PnPOnline -Url $SourceUrl -UseWebLogin
$ServerRelativeUrl=(Get-PnPWeb).ServerRelativeUrl
#Get all source pages
$pages = Get-PnPListItem -List sitepages
Foreach($page in $pages){
$pageName = $page.FieldValues["FileLeafRef"]
#if($pageName -like "Migrated*"){ #OPTIONAL FILTER
#Write-Host $pageName
$file = Get-PnPFile -Url "$ServerRelativeUrl/sitePages/$pageName"
$fileServerRelativeUrl = Get-PnPProperty -ClientObject $file -Property "ServerRelativeUrl"
#Start the move
Move-PnPFile -ServerRelativeUrl $fileServerRelativeUrl -TargetServerRelativeLibrary $targetRelativeLibraryUrl -Force -AllowSchemaMismatch -AllowSmallerVersionLimitOnDestination
#}
}
- David2FelixJan 18, 2021Copper Contributor
pgawde_800 I solved using PNP-PoweShell, afterwards I only had to upload the images to the Image WebParts.
try{
$srcSiteURL = "https://xxxxx.sharepoint.com/sites/xxxxx/"
$destSiteURL = "https://xxxxx.sharepoint.com/sites/yyyyy/"
$pageName = "test.aspx"
Connect-PnPOnline -Url $srcSiteURL -Credentials SharepointCredential
$tempFile = [System.IO.Path]::GetTempFileName();
Export-PnPClientSidePage -Force -Identity $pageName -Out $tempFile
Connect-PnPOnline -Url $destSiteURL -Credentials SharepointCredential
Apply-PnPProvisioningTemplate -Path $tempFile
Write-Host "Success"
}
catch{
Write-Host -ForegroundColor Red 'Error ',':'$Error[0].ToString();
}
- ka-techJul 23, 2021Copper Contributor
David2Felix
I have managed to do this, however I am missing the images - what are the steps to get the content from the source page over to the destination page?I can not even see the images in the pages from the source content SharePoint site stored anywhere in document libraries.
Thanks for any help!