If you’re looking to set up the Office 365 Public CDN in SharePoint Online, you can use the following PowerShell scripts. I installed the June 2017 Release of the SharePointPnP.PowerShell Commands for this post.
After you run the script, your changes will take affect within 15 minutes. The files stored in the CDN can only be accessed within the context of SharePoint so if you try to browse to the CDN url for your asset, it will not work; however, if you reference the same url in SharePoint, it will work.
The CDN url will look like: https://publiccdn.sharepointonline.com/.sharepoint.com//
$spo = Read-Host 'Enter your SPO Service URL. (example https://<tenant>-admin.sharepoint.com)' $origin = Read-Host 'Enter the url to the CDN. (example https://<tenant>.sharepoint.com/sites/Media/CDNLibrary)' connect-sposervice $spo $tenant = Get-SPOTenant Set-SPOTenant -PublicCdnEnabled $true $tenant = Get-SPOTenant Write-host 'Public Cnd Enabled = ' $tenant.PublicCdnEnabled Write-host 'Allowed File Types = ' $t.PublicCdnAllowedFileTypes New-SPOPublicCdnOrigin -url $origin
If you need to get the Origin ID, you can find it with the following script.
$tenant = Get-SPOTenant $tenant.PublicCdnOrigins
Updated: February 13, 2018
The above PowerShell works with a previous version of the SharePoint Management Shell. As of this update, we are on version 16.0.7317.1200. There are some new commands.
$spo = Read-Host 'Enter your SPO Service URL. (example https://<tenant>-admin.sharepoint.com)' $origin = Read-Host 'Enter the url to the CDN. (example sites/Media/CDNLibrary)' connect-sposervice $spo #This may take up to 15 minutes to update Set-SPOTenantCdnEnabled -CdnType Public #This may also take up to 15 minutes to update Add-SPOTenantCdnOrigin -CdnType Public -OriginUrl $origin