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()