pnp / PnP-PowerShell

SharePoint PnP PowerShell CmdLets
https://pnp.github.io/powershell
Other
990 stars 663 forks source link

Add parameter Properties to Add-PnPFileToProvisioningTemplate #1364

Open ruslanurban opened 6 years ago

ruslanurban commented 6 years ago

Missing Feature | Enhancement

PnP Scheme allows specifying a list of parameters for pnp:File elements. It woudl be great to extend the Add-PnPFileToProvisioningTemplate cmdlet with a parameter [System.Collections.IDictionary] Properties (See https://github.com/SharePoint/PnP-Provisioning-Schema/blob/master/ProvisioningSchema-2018-01.md#file).

Similarly, add ability to define pnp:WebParts and pnp:Security definitions on the generated pnp:File elements.

Expected behavior

Example:

$properties = [ordered]@{
    "ContentTypeId"="{contenttypeid:Html Master Page}";
    "Title"="Master Page with Corporate Branding";
    "HtmlDesignFromMaster"="{masterpagecatalog}/corporate.html, {masterpagecatalog}/corporate.html";
    "HtmlDesignAssociated"="True";
}

Add-PnPFileToProvisioningTemplate `
    -Path $templatePath `
    -Container "Files\_catalogs\masterpage" `
    -Source '.\_catalogs\masterpage\corporate.html' `
    -Folder "{site}/_catalogs/masterpage" `
    -FileLevel Published `
    -Properties $properties;

The template shall contain the following File entry.

<pnp:File Src="Files\_catalogs\masterpage\corporate.html" Folder="{masterpagecatalog}" Overwrite="true" Level="Published">
    <pnp:Properties>
        <pnp:Property Key="ContentTypeId" Value="{contenttypeid:Html Master Page}" />
        <pnp:Property Key="Title" Value="Master Page with Corporate Branding" />
        <pnp:Property Key="HtmlDesignFromMaster" Value="{masterpagecatalog}/corporate.html, {masterpagecatalog}/corporate.html" />
        <pnp:Property Key="HtmlDesignAssociated" Value="True" />
    </pnp:Properties>
</pnp:File>

Actual behavior

N/A

How did you install the PnP-PowerShell Cmdlets?

Which version of the PnP-PowerShell Cmdlets are you using?

erwinvanhunen commented 6 years ago

Interesting idea. you can however do something similar in the following way, it's maybe a bit more elaborate, but it has the same effect.

Add-PnPFileToProvisioningTemplate -Path $templatePath -Container "Files\_catalogs\masterpage" -Source '.\_catalogs\masterpage\corporate.html' -Folder "{site}/_catalogs/masterpage" -FileLevel Published
$template = Load-PnPProvisioningTemplate -Path $templatePath
# Here we add properties to the first file element in the template
$template.Files[0].Properties.Add("ContentTypeId","{contenttypeid:Html Master Page}")
$template.Files[0].Properties.Add("Title","Master Page with Corporate Branding")
$template.Files[0].Properties.Add("HtmlDesignFromMaster","{masterpagecatalog}/corporate.html, {masterpagecatalog}/corporate.html")
$template.Files[0].Properties.Add("HtmlDesignAssociated","True")
Apply-PnPProvisioningTemplate -InputInstance $template
ruslanurban commented 6 years ago

Thank you for the sample Ervin. Hope to see the enhancement implemented in the framework because the functionality is implied by the schema.