Forum Discussion
Copy page/news template between sites using powershell
Hi.
I'd like to be able to create a page/news template on site A, and copy it over site B. I found a way to copy files over from site A to site B by running something like Get-PnPFile to download the template from site A, and Add-PnPFile -Path './mytemplate.aspx' -Folder 'templates' to upload the file to site B's "templates"-folder, but on site B the template is not listed under the templates gallery when creating new pages/news, so I must have missed something.
Any pointers as to how to both copy the template file and also get it to appear on site B's templates gallery will be appreciated.
Hi,
You need to have at least one template created before copied files are visible on Templates gallery. I noticed this when copying templates over with Power Automate.
I have been using PnP Provisioning Template to copy page templates between sites. If you are interested, you can check out my blog post about this topic.
https://mattipaukkonen.com/2020/07/02/distribute-sharepoint-page-templates-with-pnp-powershell-and-provisioning-templates/Idea is first get all client side pages to a provisioning template, create a new template object with just page templates and apply it to a target site.
5 Replies
- Matti PaukkonenIron Contributor
Hi,
You need to have at least one template created before copied files are visible on Templates gallery. I noticed this when copying templates over with Power Automate.
I have been using PnP Provisioning Template to copy page templates between sites. If you are interested, you can check out my blog post about this topic.
https://mattipaukkonen.com/2020/07/02/distribute-sharepoint-page-templates-with-pnp-powershell-and-provisioning-templates/Idea is first get all client side pages to a provisioning template, create a new template object with just page templates and apply it to a target site.
- kennehoBrass Contributor
Matti Paukkonen , copying the templates works perfectly. However, when I have a template containing images, and copy that template to a new site, we find that the image doesn't seem to get copied. Is this a case even for you? Have you found a way to get this working?
- Matti PaukkonenIron Contributor
Hi kenneho,
You can include images to a template by adding -PersistBrandingFiles handle, for example
$basetemplate = Get-PnPProvisioningTemplate -IncludeAllClientSidePages -Handlers PageContents,Pages -OutputInstance -Schema LATEST -PersistBrandingFilesIf you are creating a new template, like in my blog post, you need to add Files.
$template.Files.AddRange($basetemplate.Files)Example above is actually adding all image from SiteAssets library.
Hope this helps! Blog post examples also updated.
- kennehoBrass Contributor
Matti Paukkonen I got things working exactly as needed, thanks to your script. Again, thanks!
- kennehoBrass Contributor
Thanks, this seems to be exactly what I'm looking for! I'll check it out.