0

My requirement is to configure the properties of Highlighted Content WP on Sharepoint online modern page using PnP Powershell. I have used Set-PnPClientSideWebPart command but i am unclear about how should my JSON string should be for [-PropertiesJson ] option.

I need to add 2 other different sharepoint sites for the Filter criteria with Source as "Select Sites" as shown in screenshot. Other properties should be as below

  1. Type = Documents
  2. Document Type - Any
  3. Sort By - Most Recent
  4. Layout - FilmStrip
  5. No of items to show is 100

NOTE : I need to do this for hundreds of sites and cannot do it manually and looking for automation options.

enter image description here

1
  • Check this and this. These should give you the basic idea of how to set WebPartProperties using PnP PowerShell for Highlighted content webpart. Aug 26, 2020 at 5:20

2 Answers 2

1

The JSON string for a configured Highlighted Content web part can be retrieved using the following script:

Connect-PnPOnline -Url <siteURL>
$page = Get-PnPClientSidePage -Identity <PageName>
$page.controls

Here is the output: enter image description here

Find the Highlighted Content web part property InstanceId, and then you can retrieve the JSON string by executing:

$webpart = $page.Controls | ? {$_.InstanceId -eq "<InstanceId of the Highlighted Content WP>"}  
$webpart.PropertiesJson

Reference:Working with modern client-side pages using PnP PowerShell

A sample from my test result:

{
    "displayMaps":{
        "1":{"headingText":{"sources":["SiteTitle"]},"headingUrl":{"sources":["SPWebUrl"]},"title":{"sources":["UserName","Title"]},"personImageUrl":{"sources":["ProfileImageSrc"]},"name":{"sources":["Name"]},"initials":{"sources":["Initials"]},"itemUrl":{"sources":["WebPath"]},"activity":{"sources":["ModifiedDate"]},"previewUrl":{"sources":["PreviewUrl","PictureThumbnailURL"]},"iconUrl":{"sources":["IconUrl"]},"accentColor":{"sources":["AccentColor"]},"cardType":{"sources":["CardType"]},"tipActionLabel":{"sources":["TipActionLabel"]},"tipActionButtonIcon":{"sources":["TipActionButtonIcon"]},"className":{"sources":["ClassName"]}},"2":{"column1":{"heading":"","sources":["FileType"],"width":34},"column2":{"heading":"Title","sources":["Title"],"linkUrls":["WebPath"],"width":250},"column3":{"heading":"Modified","sources":["ModifiedDate"],"width":100},"column4":{"heading":"Modified By","sources":["Name"],"width":150}},"3":{"id":{"sources":["UniqueID"]},"edit":{"sources":["edit"]},"DefaultEncodingURL":{"sources":["DefaultEncodingURL"]},"FileExtension":{"sources":["FileExtension"]},"FileType":{"sources":["FileType"]},"Path":{"sources":["Path"]},"PictureThumbnailURL":{"sources":["PictureThumbnailURL"]},"PreviewUrl":{"sources":["PreviewUrl"]},"SiteID":{"sources":["SiteID"]},"SiteTitle":{"sources":["SiteTitle"]},"Title":{"sources":["Title"]},"UniqueID":{"sources":["UniqueID"]},"WebId":{"sources":["WebId"]},"WebPath":{"sources":["WebPath"]}},"4":{"headingText":{"sources":["SiteTitle"]},"headingUrl":{"sources":["SPWebUrl"]},"title":{"sources":["UserName","Title"]},"personImageUrl":{"sources":["ProfileImageSrc"]},"name":{"sources":["Name"]},"initials":{"sources":["Initials"]},"itemUrl":{"sources":["WebPath"]},"activity":{"sources":["ModifiedDate"]},"previewUrl":{"sources":["PreviewUrl","PictureThumbnailURL"]},"iconUrl":{"sources":["IconUrl"]},"accentColor":{"sources":["AccentColor"]},"cardType":{"sources":["CardType"]},"tipActionLabel":{"sources":["TipActionLabel"]},"tipActionButtonIcon":{"sources":["TipActionButtonIcon"]},"className":{"sources":["ClassName"]}}
    },
    "query":{"contentLocation":5,"contentTypes":[1],"sortType":1,"filters":[{"filterType":1,"value":""}],"documentTypes":[99]},
    "templateId":4,"maxItemsPerPage":100,"hideWebPartWhenEmpty":false,"sites":[],"queryMode":"Basic","layoutId":"FilmStrip","dataProviderId":"Search","webId":"<webId>","siteId":"<siteId>"
}

You can also see the link here for a sample json file (original blog can be found via the first link from @Ganesh Sanap’s comment).

0

Realize this is old, this cmdlet is deprecated and you'll need to use Set-PnPPageWebPart:

store your json in a variable and then simply: -PropertiesJson ( $jsonProp | ConvertTo-Json )

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.