PNP Template Provisioning Document Sets

Copper Contributor

I am trying to create a PNP Provisioning template of a site and then apply this to other modern sites, but one of the content types on it is not playing ball. It's a document set and in the properties it has default content of 5 files to create 5 folders. I don't need the files but, at least through the GUI, you have to put dummy files in to create 5 folders automatically when the document set is created, which is the brief. When I create the provisioning XML, all the default files are stripped out of the document set content type.

 

How do I go about doing this in PNP? I would settle for how to do this in PowerShell against an SPOSite, as I could run it after creation of the main sites from the templates. 

5 Replies

Not sure if it helps your exact case, but if you look at the latest PnP Provisioning Schema at line 310, you can see how to handle document sets with default content. The sample doesn't seem to include any default folders, but maybe you can find something to help you.

 

https://github.com/SharePoint/PnP-Provisioning-Schema/blob/master/Samples/ProvisioningSchema-2018-07...

I think you might be able to put a folder name in the Name field, before the filename, but the bit I still don't understand is where the FileSourcePath to the file comes from. Is the file path on the file system with the template xml or on the target site?

 

<pnp:DefaultDocument Name="Attendance.txt" ContentTypeID="0x010100FE20F6E69ED0FB40AFAA895B47A533D8" FileSourcePath="./libraries/Attendence.txt" />

So the default document will be the path to an actual document that you will include in the same folder as your template.xml file. So let's say you create a folder on your c: drive called "mypnptemplate" and inside it you have your some files such as "Attendance.txt", along with the provisioning template itself, "template.xml", which references those within that same folder using the relative path (eg. ./Attendance.txt)

 

You would then "zip" that folder up as a PnP package file:

 

Then with PnP PowerShell, you run: Convert-PnPFolderToProvisioningTemplate -Out template.pnp -Folder c:\mypnptemplate

 

You need to name the .pnp file the same as the .xml file within the folder via the "-Out" parameter.

 

This will create a .pnp package file - an Open XML file - including your artifacts (documents in your case) and references to them within the provisioning template. If you then Apply-PnPProvisioningTemplate using the .pnp file, you will provision your template along with the included artifacts (documents).

 

Convert-PnPFolderToProvisioningTemplate:

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/convert-pnpfoldertoprovisioningtem...

 

Full details about PnP Package files and including artifacts:

https://www.erwinmcm.com/getting-started-with-the-pnp-provisioning-engine-and-pnp-powershell/

Thanks so much for this, it works beautifully now. I'm using the solution to create Document sets containing 5 folders automatically, so through the interface I upload a dummy file to each folder path. Can this also be done using the PNP template as I don't see anywhere to enter the folder path?

I'm not sure you can provision folders like that within document sets in the Provisioning Schema. I think you might have to go edit the document set content type's Welcome Page property with PowerShell after it has been created in order to do that - not 100% whether you can even do that or not.