Add-PnPClientSideWebPart -Page "" -Component "" -WebPartProperties ""
Explanation of Parameters
Page - Accepts String
Component - Accepts String
WebPartProperties - Accepts JSON Object
JSON Object can be as simple as:
$jsonObj = @"
{
"Property1": "value",
"Property2": "value"
}
"@
Sometimes, one can easily add webparts from the userinterface, and hard to identify the property names to configure the webpart. In those scenarios, use this:
$page = Get-PnPClientSidePage -Identity ""
Explanation of parameters
Identity - Accepts String (example: home.aspx)
$webpart = $page.Controls | ? {$_.InstanceId -eq "GUID string"}
Explanation of parameters
GUID String can be accessed from the Source control of the page (from UI)
$webpart.PropertiesJson
Will reveal the properties in JSON Format, that can be used as is in the First command above to add webpart on the page.
Source:
Self, and
Working with modern client-side pages using PnP PowerShell
No comments:
Post a Comment