Setting up your Office 365 CDN with PnP Provisioning or PnP PowerShell
The upcoming build of the PnP Provisioning Engine now allows you to configure your tenant CDN settings through a template. In this short post I show you how to configure your CDN with both the PnP Provisioning Engine and PnP PowerShell
PnP Provisioning
While the current schema (2018-01) already supports these elements, the actual engine does not implement them yet. We will release this functionality in the April 2018 (2.25.1804.0) release.
Take the following snippet:
<pnp:Tenant>
<pnp:ContentDeliveryNetwork>
<pnp:Public Enabled="true">
<pnp:Origins>
<pnp:Origin Url="sites/CDN/PublicCDN" Action="Add" />
</pnp:Origins>
<pnp:IncludeFileExtensions>PDF,XML,JPG,JS,PNG</pnp:IncludeFileExtension>
<pnp:ExcludeRestrictedSiteClassifications>HBI,GDPR</pnp:ExcludeRestrictedSiteClassifications>
</pnp:Public>
<pnp:Private Enabled="true">
<pnp:Origins>
<pnp:Origin Url="sites/CDNPrivate/PrivateCDN" Action="Add" />
</pnp>
</pnp:Private>
</pnp:ContentDeliveryNetwork>
</pnp:Tenant>
You can now enable or disable the public CDN, add or remove origins, specify file extensions to include and exclude site classifications.
It is important to understand that these settings are made on tenant level. This means that the element does not reside in the <pnp:ProvisionTemplate>
element but higher up in the tree:
<pnp:Provisioning xmlns:pnp="http://schemas.dev.office.com/PnP/2018/01/ProvisioningSchema">
<pnp:Preferences Generator="OfficeDevPnP.Core, Version=2.25.1804.1, Culture=neutral, PublicKeyToken=5e633289e95c321a">
...
</pnp:Preferences>
<pnp:Tenant>
<pnp:ContentDeliveryNetwork>
<pnp:Public Enabled="true">
<pnp:Origins>
<pnp:Origin Url="sites/CDN/CDNPublic" Action="Add" />
</pnp:Origins>
</pnp:Public>
</pnp:ContentDeliveryNetwork>
</pnp:Tenant>
<pnp:Templates ID="MY-TEMPLATES">
<pnp:ProvisioningTemplate ID="MY-TEMPLATE" Version="1.0" BaseSiteTemplate="SITEPAGEPUBLISHING#0" ImagePreviewUrl="https://preview.png" DisplayName="..." Description="" Scope="RootSite" TemplateCultureInfo="1033">
...
</pnp:ProvisioningTemplate>
</pnp:Templates>
</pnp:Provisioning>
PnP PowerShell
We have a few cmdlets available in PnP PowerShell that allow you to set the same settings
Enabling and Disabling
Set-PnPTenantCdnEnabled -Enable [$true|$false] -CdnType [Public|Private|Both]
Get-PnPTenantCdnEnabled -CdnType [Public|Private]
Managing origins
To specify the origins of your CDN, set the URLs using the following cmdlets:
Get-PnPTenantCdnOrigin -CdnType [Public|Private]
Add-PnPTenantCdnOrigin -OriginUrl [string] -CdnType [Public|Private]
Remove-PnPTenantCdnOrigin -OriginUrl [string] -CdnType [Public|Private]
Managing Policies
To set values like which file extensions to include, or which site classifications to exclude, use the CdnPolicy cmdlets:
Get-PnPTenantCdnPolicies -CdnType [Public|Private]
Set-PnPTenantCdnPolicy -CdnType [Public|Private] -PolicyType [IncludeFileExtensions|ExcludeRestrictedSiteClassifications|ExcludeIfNoScriptDisabled] -PolicyValue [string]