question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Get-PnPSiteTemplate Error While Generating Template

See original GitHub issue

Reporting an Issue or Missing Feature

The Get-PnPSiteTemplate is failing to create a template for a given site. I’ve tested the site beforehand with Test-PnPSite and no errors were found.

Expected behavior

The Get-PnPSiteTemplate command should create an XML template representing the given site.

Actual behavior

The command is returning the following error:

Get-PnPSiteTemplate : Oops...seems we end up here anyway...check PnP.Framework code to understand what was here
At C:\Users\joaosalgado\workspace\SharePointBackupTools\src\Export-SharePointSiteTemplate.ps1:45 char:9
+         Get-PnPSiteTemplate `
+         ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Get-PnPSiteTemplate], Exception
    + FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Provisioning.Site.GetSiteTemplate

After running Get-PnPException I got the following stack:

Message          : Oops...seems we end up here anyway...check PnP.Framework code to understand what was here
Stacktrace       :    at PnP.Core.Model.SharePoint.PageWebPart.FromHtml(IElement element)
                      at PnP.Core.Model.SharePoint.Page.LoadFromHtml(String html, String pageHeaderHtml)
                      at PnP.Core.Model.SharePoint.Page.<LoadPageAsync>d__121.MoveNext()
                   --- End of stack trace from previous location where exception was thrown ---
                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      at PnP.Core.Model.SharePoint.Page.<LoadPagesAsync>d__93.MoveNext()
                   --- End of stack trace from previous location where exception was thrown ---
                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                      at PnP.Core.Model.SharePoint.Web.<GetPagesAsync>d__282.MoveNext()
                   --- End of stack trace from previous location where exception was thrown ---
                      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                      at PnP.Core.Model.SharePoint.Web.GetPages(String pageName)
                      at Microsoft.SharePoint.Client.PageExtensions.LoadClientSidePage(Web web, String pageName)
                      at PnP.Framework.Provisioning.ObjectHandlers.Utilities.ClientSidePageContentsHelper.ExtractClientSidePage(Web 
                   web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope 
                   scope, PageToExport page)
                      at PnP.Framework.Provisioning.ObjectHandlers.ObjectClientSidePageContents.ExtractObjects(Web web, 
                   ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
                      at PnP.Framework.Provisioning.ObjectHandlers.SiteToTemplateConversion.GetRemoteTemplate(Web web, 
                   ProvisioningTemplateCreationInformation creationInfo)
                      at PnP.PowerShell.Commands.Provisioning.Site.GetSiteTemplate.ExtractTemplate(XMLPnPSchemaVersion schema, 
                   String path, String packageName, ExtractConfiguration configuration)
                      at PnP.PowerShell.Commands.Provisioning.Site.GetSiteTemplate.ExecuteCmdlet()
                      at PnP.PowerShell.Commands.PnPSharePointCmdlet.ProcessRecord()

Steps to reproduce behavior

Just run the following command in a Powershell session.

        Get-PnPSiteTemplate `
            -Out $TemplatePath `
            -IncludeAllTermGroups `
            -IncludeSiteCollectionTermGroup `
            -IncludeSiteGroups `
            -PersistBrandingFiles `
            -PersistPublishingFiles `
            -IncludeNativePublishingFiles `
            -IncludeAllPages `
            -Handlers All `
            -Schema LATEST `
            -Force;

What is the version of the Cmdlet module you are running?

1.5.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
teofilosalgadocommented, Apr 16, 2021

Yeah, exactly. Here is a snippet of my template extraction code:

Connect-PnPOnline -Url $Url -UseWebLogin;
$PageList = Get-PnPListItem -List "SitePages";
$ResultPath = Resolve-Path ".\Result";

foreach ($PageItem in $PageList) {
    $Name = $PageItem.FieldValues["FileLeafRef"];
    $Guid = $PageItem.FieldValues["GUID"];
    $TemplateFolderPath = Join-Path -Path $ResultPath -ChildPath $Guid;
    $TemplateFilePath = Join-Path -Path $TemplateFolderPath -ChildPath "Template.xml";

    Export-PnPClientSidePage `
         -Identity $Name `
         -Out $TemplateFilePath `
         -PersistBrandingFiles `
         -ErrorAction Stop `
         -Force;
}

And the script that applies the templates:

Connect-PnPOnline -Url $DestinationUrl -UseWebLogin;
$Templates = Import-Csv -Path ".\Result\Log.csv"; # Log.csv is a list of every template and it's location in the disk

foreach($Template in $Templates){
    $TemplatePath = $Template.Path;
    Apply-PnPProvisioningTemplate -Path $TemplatePath -ClearNavigation;
}

It works flawlessly for team and communication sites. No throttle or disconnections during the entire process which took around 1 hour in a 150mbits/s network.

1reaction
teofilosalgadocommented, Apr 15, 2021

Hi @jansenbe! So, I checked all of my pages and none of them contain 3rd party web parts or additional controls in their headers. Actually, most of my pages are just plain text with a few tables. Currently, as a workaround, I decided to create a template for every single page of my website using Export-PnPClientSidePage and later on iterating through each .XML file publishing the templates with Export-PnPClientSidePage. I will give the nightly builds a try tonight.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Method Not Found" Error while using Get-PnPSiteTemplate
Sounds like there is a bug with the most recent version (v1.7 and ... Get-PnPProvisioningTemplate is not recognized as the name of a...
Read more >
Get-PnPSiteTemplate : Attempted to perform an ...
I am trying to export a design template for a site that I am in the Owners group for, and I have Share...
Read more >
Apply-PnPProvisioningTemplate : File not Found
There is a bug in the provisioning schema causing this error. try to find the field Name="_DisplayName" within your template.xml (there are ...
Read more >
PnP Provisioning Template error - Invalid template URL
My source site contains a library with a folder content type that includes a description field. Is that what may be causing the...
Read more >
Why does Apply-PnPProvisioningTemplate PNP command ...
As a general rule: use only characters (not even numbers) in column names. Don't use spaces, dashes, underscores, or anything other than ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found