top of page
  • Writer's pictureKasper Larsen

Store your PnP Provisioning .pnp and .xml files in SharePoint

Updated: Jun 25

Two of the really awesome features in PnP Provisioning is

  1. The ability to invoke a template file stored in SharePoint. This is particularly handy in Azure Functions or Runbooks as you don't have to store the template file temporarily.

2. The second feature is the ability to use parameters in the template.

This is very useful in situations where the same template is applied serveral times but with a different set of values.

In a resent case I had a template containing a specific list, including content types, default column values, multiple views and even a bit of json based View formatting.

However, the name and the URL of the list depended on which customer

(managed metadata) the list was created for.

Parameters are just perfect in this case.

This issue:

Unfortunately, for some reason Invoke-PnPSiteTemplate only supports the .pnp file format when getting the template file from a location within SharePoint.

And the option to use parameters is only supported for the XML file format...... what to do, as I needed both?

I decided to walk the dog, as this allows my subconscious to work on a solution. And I found a solution:

First read the template file as a memory stream, hand it over to Read-PnPSiteTemplate in order to get the Input Instance that Invoke-PnPSiteTemplate can use:

$stream = Get-PnPFile -Url $PnPXMLTempleatePath -AsMemoryStream -Connection $PnPXMLTempleateSiteConn
$templateasstream = Read-PnPSiteTemplate -Stream $stream
$targetconn = Connect-PnPOnline -Url $siteUrl -Interactive -ReturnConnection
Invoke-PnPSiteTemplate -InputInstance $templateasstream -Connection $targetconn -Parameters @{"ListTitle"="Projects";"ListUrl"="Pics"}

Last step is just to update Parameters to take a variable and the Azure Function is almost complete :-)

81 views0 comments


bottom of page