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>
So I tried adding -ExcludeHandlers Publishing to my Apply-PnPProvisioningTemplate command but that didn’t work.
My workaround
I was exporting the template form an existing site using:
Get-PnPProvisioningTemplate -Out $templateFile -Web templates/departmenttemplate
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

Leave a Reply
You must be logged in to post a comment.