Script to add SPFx webpart to a classic page using PnP Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-244967%22%20slang%3D%22en-US%22%3EScript%20to%20add%20SPFx%20webpart%20to%20a%20classic%20page%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-244967%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20to%20run%20a%20Powershell%20script%20that%20creates%20a%20Site%20Collection%20App%20catalog%20%2C%20then%20add%20an%20SPFx%20webpart%20to%20it%20and%20publish%20it.%20Also%20it%20has%20to%20install%20it%20in%20the%20site.%20I%20have%20done%20upto%20this%20part.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELast%20piece%20missing%20is%20to%20%3CSTRONG%3Eadd%20it%20to%20a%20classic%20page%3C%2FSTRONG%3E.%20I%20can%20see%20adding%20to%20modern%20pages.%20but%20i%20need%20to%20add%20it%20to%20a%20classic%20page.%20I%20have%20seen%20this%20post%20-%26nbsp%3B%3CSTRONG%3E%3CU%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSharePoint-Developer%2FPnP-PowerShell-Adding-SPFx-web-part-to-a-classic-page%2Fm-p%2F169570%23M4531%22%20target%3D%22_blank%22%3Ehttps%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FSharePoint-Developer%2FPnP-PowerShell-Adding-SPFx-web-part-to-a-classic-page%2Fm-p%2F169570%23M4531%3C%2FA%3E%3C%2FU%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20it%20has%20a%20step%20to%20manually%20add%20SPFx%20app%20to%20a%20classic%20page%20and%20to%20get%20the%20XML.%26nbsp%3BThis%20is%20not%20possible%20in%20my%20case%20as%20I%20have%20to%20automate%20everything.%26nbsp%3BIs%20there%20way%20to%20achieve%20my%20need%20or%20to%20tweak%20the%20method%20provided%20in%20the%20post.%3C%2FP%3E%3CP%3EAs%20far%20my%20code%20is%20-%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAdd-PnPSiteCollectionAppCatalog%20-Site%20%24url%3CBR%20%2F%3EAdd-PnPApp%20-Path%20D%3A%2Fcustom.sppkg%20-Scope%20Site%20-Publish%3CBR%20%2F%3EInstall-PnPApp%20-Identity%26nbsp%3B%22custom-webpart%22%20-Scope%20Site%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-244967%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Regular Visitor

I have to run a Powershell script that creates a Site Collection App catalog , then add an SPFx webpart to it and publish it. Also it has to install it in the site. I have done upto this part.

 

Last piece missing is to add it to a classic page. I can see adding to modern pages. but i need to add it to a classic page. I have seen this post - https://techcommunity.microsoft.com/t5/SharePoint-Developer/PnP-PowerShell-Adding-SPFx-web-part-to-a...

 

But it has a step to manually add SPFx app to a classic page and to get the XML. This is not possible in my case as I have to automate everything. Is there way to achieve my need or to tweak the method provided in the post.

As far my code is - 

 

Add-PnPSiteCollectionAppCatalog -Site $url
Add-PnPApp -Path D:/custom.sppkg -Scope Site -Publish
Install-PnPApp -Identity "custom-webpart" -Scope Site

 

0 Replies