0

I want to copy one site to another clean site. I did it a few times weeks ago and it works good. Now I get an error: File Not Found during export template to pnp file. Any idea why?

Connect-PnPOnline -PnPManagementShell -Url https://XXX.sharepoint.com/sites/MDMS

Get-PnPProvisioningTemplate -Out prototype.pnp -IncludeAllClientSidePages

Connect-PnPOnline -PnPManagementShell -Url https://XXX.sharepoint.com/sites/PolishFuncApp

Apply-PnPProvisioningTemplate .\prototype.pnp -ClearNavigation

enter image description here

I turned on Set-PnPTraceLog enter image description here

1
  • Can you try to connect without the "-PnPManagementShell" param? After the error occurred you can use Get-PnPException to get the stack trace. I didn't know about Set-PnPTraceLog. Thx for that one!
    – engineerer
    Nov 27 '20 at 16:44
0

I found a solution. It turns out that PnP has changed cmdlet

enter image description here

https://github.com/pnp/powershell

0

Extracts a provisioning template in PNP format from the current web and all client side pages (if set) from the site collection.

Get-PnPProvisioningTemplate -Out template.pnp -IncludeAllClientSidePages

It may be because the prototype.pnp template file does not exist in the scope of the website you specified. Please click the Get-PnPProvisioningTemplate link for more information

You could refer to the following pnp powershell:

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"

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

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

You could refer to the following article to get more information:

…………………………………………………Updated Answer……………………………………………

Please follow the steps below to achieve the Copy a Site Collection in SharePoint Online:

Step 1: Connect to the Source site and Get its Schema

#Set variables
$SiteURL = "https://test.spo.com/sites/projects "
$SchmaXMLPath = "C:\Temp\SiteSchema.xml"
 
#Connect to PnP Online
Connect-PnPOnline -Url $siteUrl -UseWebLogin
 
#Get Site Schema
Get-PnPProvisioningTemplate -Out ($SchmaXMLPath) -PersistBrandingFiles -PersistPublishingFiles

Step 2: Create a New Site Collection or Subsite

Note:If you have clean site collection, you can skip this step
#Set variables
$SiteURL = "https://test.spo.com/"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Create a new subsite
$NewWeb = New-PnpWeb -Title "New Project" -Url "sites/new" -Description "Team Site for Morocco Project" -Locale 1033 -Template "STS#3"

Step 3: Apply the Site Schema into Target Site with Apply-PnP ProvisioningTemplate

#Set variables
$SiteURL = "https://test.sharepoint.com/sites/new"
$SchmaXMLPath = "C:\Temp\SiteSchema.xml"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
 
#Apply Pnp Provisioning Template
Apply-PnPProvisioningTemplate -Path $SchmaXMLPath -ClearNavigation

You could refer to this article:How to Copy a Site in SharePoint Online using PowerShell.

………………………………………………Updated Answer………………………………………… Please try to use the following pnp powershell:

#Connect to the Source site
$SiteURL= "https://test.spo.com/sites/echo"
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Export the template
Get-PnPProvisioningTemplate -Out “D:\Test.xml”

#Create new site if your site is not created already
New-PnPSite -Type CommunicationSite -Title 'TESTCommun' -URL https://test.spo.com/sites/echo22

#Or
#New-PnPSite -Type TeamSite -Title 'TESTTeam' -Alias 'Testsite' -IsPublic -URL https://test.spo.com/sites/echo22

#Connect to new site
Connect-PnPOnline -Url https://test.spo.com/sites/echo22 -UseWebLogin

#Import the template
Apply-PnPProvisioningTemplate -Path “D:\Test.xml”

You coulde refer to this article Sharepoint PNP: How to copy/clone a SharePoint online site.

4
  • Thank you EchoDu but your solution copy only one page. I need to copy whole site - all lists, pages navigations etc.
    – Maciej
    Dec 1 '20 at 11:08
  • Hi, MAciej. I have updated my answer, hope this helps you.Have a nice day! Dec 2 '20 at 1:42
  • Thank you EchoDu but I found that PnP has changed cmdlet.
    – Maciej
    Dec 3 '20 at 7:47
  • Hi, MAciej. I have updated my answer. I wish you all the best. Dec 3 '20 at 11:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.