Is there a PowerShell/PNP script that will update all "Highlighted Content" web parts within multiple site pages within a site? Need to update the web part Layout from "Grid" view to "List" view and don't want to have to do each manually??

Any help is appreciated.

  • one sec - i have an old script from my on-prem days that might work for this. I'm currently testing it... Dec 1, 2022 at 18:32
  • @Taco_Buffet appreciate you looking into it. Any luck?
    – Luke
    Dec 1, 2022 at 19:23
  • close, it looked as simple as updating one property, but there's a little more to it. Dec 1, 2022 at 19:50
  • Here's where I'm at: the two properties that need to be updated are layoutId and templateId. I'm struggling to get the JSON correct. The values should be something like: "layoutId" = '"list"' and "templateId" = 2 Dec 1, 2022 at 21:20
  • @Taco_Buffet Yeah thats where i am stuck at too. This is the script that runs fine but when refreshing the page, the webpart that i am testing comes back with and error saying "there is something that went wrong"
    – Luke
    Dec 1, 2022 at 21:43

1 Answer 1



Got it figured out! Here's what I used to gather all highlighted content WebParts for all site pages for a specific site. Was able to change layoutID from "Card" ("Grid" view in UI) along with also updating the max items to 500.

$Site= Get-SPOSite -Identity <SiteURL>
$pages= Get-PnPListItem -List sitepages
Foreach($page in $pages) {
    WRITE-HOST Checking $Page.FieldValues["FileLeafRef"]
    $pageName= $page.FieldValues["FileLeafRef"]
    $pg= Get-PnPClientSidePage -Identity $pageName
    $WebParts= $pg.Controls
     Foreach($WebPart in $WebParts | Where-Object {$_.Title -eq "Highlighted Content"}) {
         Write-Host Getting WebPart Instance ID
          $WPInstID= $WebPart.InstanceId 
          $WpPJ= $Webpart.PropertiesJson
     WRITE-HOST Converting from JSON
     $WpJ= ConvertFrom-Json -InputObject $WpPJ
       WRITE-HOST Changing $WPInstID to LIST VIEW
            IF($WpJ.layoutId -eq "Card") {
              $WpJ.layoutId = "List"
              $WpJ.templateId = 2
              $WpJ.maxItemsPerPage = 500}
      Set-PnPPageWebPart -Page $PageName -Identity $WPInstID -PropertiesJson (ConvertTo-JSON  $WpJ -Compress -Depth 10)
  • Good to hear you figured it out! I'm stilllll waiting for my team to authorize access to the updated pnp.powershell module. Dec 6, 2022 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.