SharePoint Online: Copy Site Pages from One Site to Another using PowerShell

Requirement: Copy site pages to another site in SharePoint Online.

SharePoint Online: How to Copy a Page to Another Site Collection?

We wanted to copy a modern page from one site to another site in SharePoint Online. The “Copy to” option doesn’t support copying site pages from one site to another.

sharepoint online copy page to another site collection

Luckily we’ve PnP PowerShell available to copy a modern page to another site:

#Parameters
$SourceSiteURL = "https://crescent.sharepoint.com/sites/marketing"
$DestinationSiteURL = "https://crescent.sharepoint.com/sites/branding"
$PageName =  "About.aspx"

#Connect to Source Site
Connect-PnPOnline -Url $SourceSiteURL -UseWebLogin

#Export the Source page
$TempFile = [System.IO.Path]::GetTempFileName()
Export-PnPClientSidePage -Force -Identity $PageName -Out $TempFile

#Import the page to the destination site
Connect-PnPOnline -Url $DestinationSiteURL -UseWebLogin
Apply-PnPProvisioningTemplate -Path $TempFile

This PowerShell script export-imports a given page along with all its web parts, contents, etc. How about copying all pages from one site to another?

PowerShell to Copy All Site Pages to Another Site in SharePoint Online

To copy all pages to another site collection, use this PowerShell script.

#Parameters
$SourceSiteURL = "https://crescent.sharepoint.com/sites/marketing"
$DestinationSiteURL = "https://crescent.sharepoint.com/sites/branding"

#Connect to the Source Site
Connect-PnPOnline -Url $SourceSiteURL -UseWebLogin

#Export all pages from the source
$TempFile = [System.IO.Path]::GetTempFileName()
Get-PnPProvisioningTemplate -Out $TempFile -Handlers PageContents -IncludeAllClientSidePages -Force

#Import the page to the destination site
Connect-PnPOnline -Url $DestinationSiteURL -UseWebLogin
Apply-PnPProvisioningTemplate -Path $TempFile

This will backup all pages in the “Site Pages” library to an XML file with all the artifacts from pages and import them to the given destination site. We can use this method to backup-restore site pages within the same tenant or between different tenants in SharePoint Online.

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

4 thoughts on “SharePoint Online: Copy Site Pages from One Site to Another using PowerShell

  • July 16, 2021 at 11:43 AM

    Hi there,

    sorry to say but this page needs to be updated.
    Get-PnPProvisioningTemplate is not existing anymore in PnP.Powershell

    Kind regards,
    Dave

    Reply
    • September 9, 2021 at 1:27 PM

      Yes! If you have upgraded to New PnP PowerShell module, PnP.PowerShell, Get-PnPProvisioningTemplate cmdlet is replaced with “Get-PnPSiteTemplate” and “Apply-PnPProvisioningTemplate” is replaced with “Invoke-PnPSiteTemplate”.

      Reply
  • July 14, 2021 at 7:15 PM

    These are great, thanks for putting in the time to share!

    Reply
  • December 29, 2020 at 12:15 PM

    Hi,
    thanks for your work.

    Is it posible that I export sides by the last modification date?
    E.g.: I would like to export all sides modified in the time between 21.12. – 27.12.

    best regards
    Raphael

    Reply

Leave a Reply