Today I tried to apply a PnP template to a publishing site and I was getting the following error.

Apply-PnPProvisioningTemplate : The object specified does not belong to a list.
At line:1 char:1
+ Apply-PnPProvisioningTemplate -Path $templateFile -Web $departmentWe …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Apply-PnPProvisioningTemplate], ServerException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Provisioning.ApplyProvisioningTemplate
I found in my template file that removing the following section would resolve the problem.
< pnp:File Src="oslo.master" Folder="{masterpagecatalog}" Overwrite="true">
< pnp:Properties>
< pnp:Property Key="ContentTypeId" Value="{contenttypeid:Master Page}" />
< pnp:Property Key="DefaultCssFile" Value="osloapp.css" />
< pnp:Property Key="_ListSchemaVersion" Value="1" />
< pnp:Property Key="_Dirty" Value="0" />
< pnp:Property Key="_Parsable" Value="1" />
< /pnp:Properties>
< /pnp:File>
< pnp:File Src="seattle.master" Folder="{masterpagecatalog}" Overwrite="true">
< pnp:Properties>
< pnp:Property Key="ContentTypeId" Value="{contenttypeid:Master Page}" />
< pnp:Property Key="DefaultCssFile" Value="corev15app.css" />
< pnp:Property Key="_ListSchemaVersion" Value="1" />
< pnp:Property Key="_Dirty" Value="0" />
< pnp:Property Key="_Parsable" Value="1" />
< /pnp:Properties>
< /pnp:File>
I added the -ExcludeHandlers Publishing here
Get-PnPProvisioningTemplate -Out $templateFile -Web templates/departmenttemplate -ExcludeHandlers Publishing
And now my master pages are excluded form the Files to be provisioned through the PnP provisioning template
More details
https://github.com/SharePoint/PnP-Sites-Core/issues/865
Discover more from SharePains
Subscribe to get the latest posts sent to your email.
Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like.
I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide.
For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions.
SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/
Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/
You can contact me using contact@sharepains.com
Is your business still running on paper trails, sprawling Excel files, or ageing Access databases? There's a better way — and I can show you exactly what it looks like.
I'm the Technical Director of Vantage 365, a Microsoft solutions consultancy working with clients across the UK, the Netherlands, and worldwide.
For over 30 years I've been turning messy, manual business processes into clean, automated systems that save time, reduce errors, and give teams the visibility they need to make better decisions.
SharePains is not just any blog run by a Microsoft MVP. Have you ever used Try-Catch in Power Automate? The original post about Try-Catch in Power Automate can still be found on this site, https://sharepains.com/2018/02/07/try-catch-finally-in-power-automate-flow/
Or have you ever used the Pieter’s method to avoid variables and speed up your flows? https://sharepains.com/2020/03/11/pieters-method-for-advanced-in-flows/
You can contact me using contact@sharepains.com
So I tried adding -ExcludeHandlers Publishing to my Apply-PnPProvisioningTemplate command but that didn’t work.
My workaround
Table of Contents
I was exporting the template form an existing site using: