0

I am generating a web page in SharePoint Online with some web parts, using PnP PowerShell.

Now I am trying to set up a Highlighted Contents web part, that should display all documents in the site where the Document Type is "My Presentation".

I have found out what the JSON for the web part should look like (using the information in Setting JSON Properties for Sharepoint Online Highlighted Content WP using PnP Powershell). But it was a lot of JSON information so I put it in a JSON file (where I also got it formatted nicely).

What would be the code to get the contents of this JSON file in the variable $myproperties so that I can use it with Set-PnPPageWebPart?


Add-PnPPage -Name "Test"
      $page = Get-PnPPage -Identity "Test.aspx"
      
      $MyPresWP = Add-PnPPageWebPart -Page $page -DefaultWebPartType “ContentRollup” -WebPartProperties @{layoutId=”Card”;title=”My Presentations”}

      $MyPresId = $MyPresWP.InstanceId
      Set-PnPPageWebPart -Page Test -Identity $MyPresId -PropertiesJson $myproperties

1

1 Answer 1

0

Try using this:

$myproperties = Get-Content -Path 'C:\path\to\your.json' | Out-String | ConvertFrom-Json

OR

$myproperties = Get-Content -Path 'C:\path\to\your.json' -Raw
2
  • -Raw did the trick!
    – Gunilla
    Commented Nov 23, 2021 at 15:10
  • Great, glad it worked for you! Commented Nov 23, 2021 at 15:16

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.