SOLVED

Copy page/news template between sites using powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-1612685%22%20slang%3D%22en-US%22%3ECopy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1612685%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EHi.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI'd%20like%20to%20be%20able%20to%20create%20a%20page%2Fnews%20template%20on%20site%20A%2C%20and%20copy%20it%20over%20site%20B.%20I%20found%20a%20way%20to%20copy%20files%20over%20from%20site%20A%20to%20site%20B%20by%20running%20something%20like%26nbsp%3B%3CFONT%20color%3D%22%230000FF%22%3EGet-PnPFile%3C%2FFONT%3E%20to%20download%20the%20template%20from%20site%20A%2C%20and%26nbsp%3B%3CFONT%20color%3D%22%230000FF%22%3EAdd-PnPFile%20-Path%20'.%2Fmytemplate.aspx'%20-Folder%20'templates'%3C%2FFONT%3E%3CFONT%20color%3D%22%23333333%22%3E%20to%20upload%20the%20file%20to%20site%20B's%20%22templates%22-folder%3C%2FFONT%3E%2C%20but%20on%20site%20B%20the%20template%20is%20not%20listed%20under%20the%20templates%20gallery%20when%20creating%20new%20pages%2Fnews%2C%20so%20I%20must%20have%20missed%20something.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EAny%20pointers%20as%20to%20how%20to%20both%20copy%20the%20template%20file%20and%20also%20get%20it%20to%20appear%20on%20site%20B's%20templates%20gallery%20will%20be%20appreciated.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1613035%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1613035%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20need%20to%20have%20at%20least%20one%20template%20created%20before%20copied%20files%20are%20visible%20on%20Templates%20gallery.%20I%20noticed%20this%20when%20copying%20templates%20over%20with%20Power%20Automate.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20been%20using%20PnP%20Provisioning%20Template%20to%20copy%20page%20templates%20between%20sites.%20If%20you%20are%20interested%2C%20you%20can%20check%20out%20my%20blog%20post%20about%20this%20topic.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fmattipaukkonen.com%2F2020%2F07%2F02%2Fdistribute-sharepoint-page-templates-with-pnp-powershell-and-provisioning-templates%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fmattipaukkonen.com%2F2020%2F07%2F02%2Fdistribute-sharepoint-page-templates-with-pnp-powershell-and-provisioning-templates%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIdea%20is%20first%20get%20all%20client%20side%20pages%20to%20a%20provisioning%20template%2C%20create%20a%20new%20template%20object%20with%20just%20page%20templates%20and%20apply%20it%20to%20a%20target%20site.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1617790%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1617790%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%2C%20this%20seems%20to%20be%20exactly%20what%20I'm%20looking%20for!%20I'll%20check%20it%20out.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1647028%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1647028%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5628%22%20target%3D%22_blank%22%3E%40Matti%20Paukkonen%3C%2FA%3E%26nbsp%3BI%20got%20things%20working%20exactly%20as%20needed%2C%20thanks%20to%20your%20script.%20Again%2C%20thanks!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1667974%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1667974%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5628%22%20target%3D%22_blank%22%3E%40Matti%20Paukkonen%3C%2FA%3E%26nbsp%3B%2C%20copying%20the%20templates%20works%20perfectly.%20However%2C%20when%20I%20have%20a%20template%20containing%20images%2C%20and%20copy%20that%20template%20to%20a%20new%20site%2C%20we%20find%20that%20the%20image%20doesn't%20seem%20to%20get%20copied.%20Is%20this%20a%20case%20even%20for%20you%3F%20Have%20you%20found%20a%20way%20to%20get%20this%20working%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1700645%22%20slang%3D%22en-US%22%3ERe%3A%20Copy%20page%2Fnews%20template%20between%20sites%20using%20powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1700645%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F423531%22%20target%3D%22_blank%22%3E%40kenneho%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20include%20images%20to%20a%20template%20by%20adding%20-PersistBrandingFiles%20handle%2C%20for%20example%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24basetemplate%20%3D%20Get-PnPProvisioningTemplate%20-IncludeAllClientSidePages%20-Handlers%20PageContents%2CPages%20-OutputInstance%20-Schema%20LATEST%20-PersistBrandingFiles%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20creating%20a%20new%20template%2C%20like%20in%20my%20blog%20post%2C%20you%20need%20to%20add%20Files.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%24template.Files.AddRange(%24basetemplate.Files)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EExample%20above%20is%20actually%20adding%20all%20image%20from%20SiteAssets%20library.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20helps!%20Blog%20post%20examples%20also%20updated.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

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.

 

 

5 Replies
best response confirmed by kenneho (Contributor)
Solution

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-p...

 

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.

Thanks, this seems to be exactly what I'm looking for! I'll check it out.

@Matti Paukkonen I got things working exactly as needed, thanks to your script. Again, thanks!

@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?

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 -PersistBrandingFiles

 

If 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.