Copy Sites Page From One Site to Another Using PNP PowerShell
Softree Technology > Blogs > PnP PowerShell > Copy Sites Page From One Site to Another Using PNP PowerShell

Copy Sites Page From One Site to Another Using PNP PowerShell

  • Posted by: Softree Technology

In this blog, we are going to discuss how to copy a modern page from one site collection to another site collection using PNP PowerShell.

To successfully copy a modern page, you have to follow the below steps:

  • PowerShell code
  • Run the script
  1. PowerShell code

Instruction: In this code, first we have to set the credential of the SharePoint. Then we export the Modern page and the page template from the source site and apply it to the destination site.

try{
$srcUrl = Read-Host "Enter the source site url"
$destUrl = Read-Host "Enter the destination site url"
$pageName = Read-Host "Enter the page name which you want to copy"
$cred = Get-Credential

Connect-PnPOnline -Url $srcUrl -Credentials $cred
$tempFile = [System.IO.Path]::GetTempFileName();
Export-PnPClientSidePage -Force -Identity $pageName -Out $tempFile

Connect-PnPOnline -Url $destUrl -Credentials $cred
Apply-PnPProvisioningTemplate -Path $tempFile
Write-Host "ModernPage is successfully copied."
sleep 10
}
catch{
Write-Host -ForegroundColor Red 'Error ',':'$Error[0].ToString();
sleep 10
} 

2. Run the script

 To get the proper result follow the below instructions:

  1. Run the script.
  2. Give the source site url from which you want to copy.
  3. Give the destination site url in which you want to copy the modern page.
  4. Type the page title which you want to copy.

5. Then it shows a popup asking for credentials. Enter your username and password then click on ok.

6. Now your modern page is copied to your destination site.



Keywords:
• Copy Modern page from one site to another using PNP PowerShell.
• Programmatically copy a modern site page using PNP PowerShell.
• Clone modern page from one site to another site using PowerShell.
• Copy Sites Page from one site to another using PNP PowerShell.

Author: Softree Technology

Leave a Reply