[BUG] Set-PnPPageWebPart set page property
Reporting an Issue or Missing Feature
I want to add a page property but I am not able to.
Expected behavior
I expect to just add the field by this cmdlet.
Actual behavior
I get an error:
Set-PnPPageWebPart : '=' is invalid after a single JSON value. Expected end of data. LineNumber: 0 | BytePositionInLine: 18.
At line:1 char:1
+ Set-PnPPageWebPart -Page $page -Identity 4e17657e-beb5-4511-b4d5-49c7 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPPageWebPart], JsonReaderException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.SetClientSideWebPart
Steps to reproduce behavior
$item = Get-PnPListItem -List "Site Pages" -Id 3
$page.Controls[0].PropertiesJson
# {"title":"","selectedFieldIds":["23f27201-bee3-471e-b2e7-b64fd8b7ca38"],"availableFields":[]}
Set-PnPPageWebPart -Page $page -Identity 4e17657e-beb5-4511-b4d5-49c73d71fedc -PropertiesJson "`"selectedFieldIds`"=`"[`"23f27201-bee3-471e-b2e7-b64fd8b7ca38`",`"ae08775f-c1d3-482e-93f5-79b833f393de`"]`""
What is the version of the Cmdlet module you are running?
1.5.0
Which operating system/environment are you running PnP PowerShell on?
- [x] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
I also tried ":" but got a similar error. According to the documentation I don't know what should be wrong here?!
This also broke for me when attempting to update a Markdown webpart. It worked a couple of weeks ago, not sure what changed. I used this for reference and it worked great.
https://github.com/pnp/PnP-PowerShell/issues/2336
I'm assuming there is no alternate way to update the markdown webpart via PNP powershell? is there a way to install an older version of pnp?
Okay. Worked with Set-PnpClientSideWebPart but why doesn't it work with Set-PnpWebPart?
confirmed - changing my script to use the old cmdlet worked for me as well. didn't update pnp to 1.7 yet as it says this cmdlet will be removed in 1.5....
i misspoke.
the commands don't work for me still. i happen to be on an older machine with the older pnp module setup. i will attempt everything again with 1.7 but as of right now this is not working still
Confirming that this is still broken.
Had to find an older machine running SharePointPnPPowerShellOnline
by the way the error I receive is:
Set-PnPPageWebPart : '0x0D' is invalid within a JSON string. The string should be correctly escaped. LineNumber: 0 |
BytePositionInLine: 97.
At C:\Users\jlu\Desktop\PnP.Powershell\functions\Set-MarkDownWebPart.ps1:35 char:13
+ Set-PnPPageWebPart -Page $homePage -Identity $components[ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPPageWebPart], JsonReaderException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.Pages.SetClientSideWebPart
My problem is solved. Went to the SharePoint disqus channel and was told that the JSON parser was changed when PnP was upgraded to .net standard.
We resolved the issue by added new escape lines for each line.
I had to add { }
-PropertiesJson "{"property":"value"}"