PnP-PowerShell icon indicating copy to clipboard operation
PnP-PowerShell copied to clipboard

Creating an in-memory provisioning template from an xml string

Open rjn71 opened this issue 7 years ago • 5 comments

All the examples I've come across for applying a provisioning template involve reading the template from a physical file path. I would like to create an in memory template reading from an xml string and then call Apply-PnPProvisioningTemplate. Reason being I'm executing the powershell script in Azure function and I'm passing the template as a string parameter to the azure function. I've tried creating a template object using New-PnPProvisioningTemplate, but after that I couldn't figure out how to set the template with the xml supplied. I looked at Read-PnPProvisioningTemplate, but that also expects a file path as input.

rjn71 avatar Apr 15 '19 15:04 rjn71

There is and XMLAzureStorageTemplateProvider for connecting to Azure storage. Its usage can be seen here in the units tests:

https://github.com/SharePoint/PnP-Sites-Core/blob/a794db71c8ea954250c5ec3a506ee04dad3b9186/Core/OfficeDevPnP.Core.Tests/Framework/Providers/XMLProvidersTests.cs#L277

But indeed it seems like there currently is no easy way to get the template directly from string. But it is definitely doable from a technical standpoint (although using PnP-Sites-Core classes).

Here are samples on how this could be implemented:

https://github.com/SharePoint/PnP-Sites-Core/blob/1397704a5cd45ee04dcdf6940a84a9f36cce6acf/Core/OfficeDevPnP.Core/Framework/Provisioning/Providers/Xml/XMLTemplateProvider.cs#L136

https://github.com/SharePoint/PnP-Sites-Core/blob/a794db71c8ea954250c5ec3a506ee04dad3b9186/Core/OfficeDevPnP.Core/Framework/Provisioning/BaseTemplates/BaseTemplateManager.cs#L54

@jansenbe is there a reason why applying a template from string (instead of file) should not be exposed?

heinrich-ulbricht avatar Apr 17 '19 15:04 heinrich-ulbricht

I'm working on a update to the engine which will allow you to initialize a provisioning template from a stream using a new provider. Together with this change I will update the Read-PnPProvisioningTemplate cmdlet to support an -Xml parameter:

$template = Read-PnPProvisioningTemplate -Xml $yourtemplatestring Apply-PnPProvisioningTemplate -InputInstance $template

erwinvanhunen avatar Apr 26 '19 16:04 erwinvanhunen

The functionality will be available in the next release of PnP PowerShell.

erwinvanhunen avatar Apr 26 '19 16:04 erwinvanhunen

Terrific!

heinrich-ulbricht avatar Apr 26 '19 18:04 heinrich-ulbricht

Thanks Erwin and Heinrich. You guys are awesome. When is the next release expected? On Friday, April 26, 2019, 7:25:06 PM GMT+1, Heinrich Ulbricht [email protected] wrote:

Terrific!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

rjn71 avatar Apr 27 '19 20:04 rjn71