Adding Quick Links webparts to Modern Pages using PnP PowerShell

Posted by

In a current project, I needed to add a quick links webpart to a new page in the site.

Note that if the page hasn’t been edited previously, the entire default contents of the page will be deleted.

Add-PnPClientSidePageSection -Page "Home" -SectionTemplate TwoColumnLeft 
if ($column.Links1) {
    Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks"  -WebPartProperties $jsonProps -Section 1 -Column 1
else {
    write-host "Blank Links"$column.URL
    Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 1 -WebPartProperties $jsonPropsGridBlankInitial

Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 2 -WebPartProperties @jsonPropsListBlankInitial
set-pnpclientsidepage -Identity $pagename -Publish:$true 

Add-PnPClientSidePageSection -Page "Home" -SectionTemplate TwoColumnLeft 

The code above creates a new section on the page ‘Home.aspx’ on the connected site. The enumeration for the -SectionTemplate parameter are:

  • OneColumn
  • OneColumnFullWidth
  • TwoColumn
  • TwoColumnLeft
  • TwoColumnRight
  • ThreeColumn

  Add-PnPClientSideWebPart -Page "Home" -DefaultWebPartType "QuickLinks" -section 1 -Column 1 -WebPartProperties $jsonPropsGridBlankInitial

This code adds the Quick Links webpart to the page. You can change th properties of the webpart by passing the -WebPartProperties value. This is a simple Json doc, an example of which is below.

$jsonPropsGridBlankInitial = @'
         "title":"Quick links",
         "description":"Add links to important documents and pages.",






The layoutid property above can be changed to ‘Grid’.

In a future post, I’ll show you how to update the Json doc above to add items to the QuickLinks webpart.

Leave a Reply