0

I am trying to build a Pnp PowerShell script that will update Highlighted Content webpart on a Modern SharePoint Online page from Grid View to List view.

I am using Convertfrom-Json and Convertto-json.

Everything looks to work for the script but when I go and refresh the SharePoint Page, it appears blank under that webpart. The plan is to eventually update all site pages containing HC webparts from Grid to List view.

$page= Get-PnPClientSidePage -Identity "TEST.aspx"
$webpart = $page.Controls | ? {$_.InstanceId -eq "<InstanceID of Specific HC webpart>"}
$WebpartJson= $webpart.PropertiesJson
$webpartobj = ConvertFrom-Json -InputObject $webpartJson
IF($webpartobj.layoutId -eq "Card") {

    $webpartobj.layoutId = "List"

}
$webpartJson = ConvertTo-Json $webpartobj -Compress
$webpart.PropertiesJson = $webpartJson
$page.Save()
$page.Publish()

1 Answer 1

0

The cmdlet you're looking for is Set-PnPPageWebPart. Here's an example of updating the property:

$wp = Get-PnPPageComponent -Page "Super-Awesome-Stuff.aspx" -InstanceId "75a66f66-a56e-4515-bf3a-628268bcbec3"
$props = ConvertFrom-Json -InputObject $wp.PropertiesJson
IF($props.layoutId -eq "Card") {
    $props.layoutId = "List"
    Set-PnPPageWebPart -Page "Super-Awesome-Stuff.aspx" -Identity "75a66f66-a56e-4515-bf3a-628268bcbec3" -PropertiesJson (ConvertTo-Json $props -Compress -Depth 10)
}
1
  • 1
    That did it! Thank You!
    – Luke
    Commented Dec 5, 2022 at 15:54

Your Answer

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

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