Forum Discussion
PnP PowerShell - Add page property web part to policy pages doesn't apply Property and Value
I've been working on a simple script to add a Page Property web part to a number of Policy pages on a site.
The following script code will add the web part with no problems but not the Column Name and value.
Add-PnPPageWebPart -Page $page -DefaultWebPartType "PageFields(1)" -Section 1 -Column 2 -Order 3 -WebPartProperties @{Property="DateofLastMaterialChange"}
Date Of Last Material Change is a Date column that the user defines when modifying any policy. I cannot get this to add the Property Name (column) and its value. Any ideas?
- LeonPavesicSilver Contributor
In your task of adding a Page Property web part to policy pages with PnP PowerShell, you've encountered an issue with configuring the Property (column) and its value. To address this, you should utilize the -WebPartProperties parameter in a specific manner.
The correct approach is to encapsulate the Property name within single quotes and employ the -WebPartProperties parameter to clearly specify the property name, such as 'DateofLastMaterialChange'. By doing so, you ensure that the Page Property web part correctly references the intended column.
Add-PnPPageWebPart -Page $page -DefaultWebPartType "PageFields(1)" -Section 1 -Column 2 -Order 3 -WebPartProperties @{ 'Property'='DateofLastMaterialChange' }
Make sure that the 'DateofLastMaterialChange' column exists in the SharePoint list or library where the policy pages are stored, and it should work as expected. If the column name or the property name is different, adjust it accordingly.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)- Kevin_Bullit_BryanCopper Contributor
LeonPavesic - Same result. The property value is not getting configured. See below the output from the script which is posted below. I still think I'm missing something in the configuration of the webpartproperties. I can't seem to find any documentation on each option for webpart and properties.
InstanceId Type Title Section Column Position PropertiesJson ---------- ---- ----- ------- ------ -------- -------------- db8c7b11-7283-4a2a-a27e-f64a5f79ddbc PageWebPart Quick links 1 2 1 {"items":[],"isMigrated":true,"layoutId":"CompactCard","layoutComponentId":"706e33c8-af37-4e7b-9d22-6e5694d92a6f","shouldShowThumbnail":true,"hideWePartWhenEmpty":"false... 537fa635-4461-4ac3-a03e-86a74b10084f PageWebPart Quick links 1 2 2 {"items":[],"isMigrated":true,"layoutId":"CompactCard","layoutComponentId":"706e33c8-af37-4e7b-9d22-6e5694d92a6f","shouldShowThumbnail":true,"hideWePartWhenEmpty":"false... b40e0942-3ef0-4463-9928-98e71b41a2b3 PageWebPart Page pro... 1 2 3 {"title":"","selectedFieldIds":[],"availableFields":[],"Property":"DateofLastMaterialChange"} AntiFraud.aspx
$page = Get-PnPPage -Identity "AntiFraud.aspx" # Add a new section with one column vertical template #Add-PnPPageSection -Page $page -SectionTemplate OneColumnVerticalSection #$page.Save() # Add web parts to the newly created section Add-PnPPageWebPart -Page $page -DefaultWebPartType "QuickLinks" -Section 1 -Column 2 -Order 1 -WebPartProperties @{title="Addenda";hideWePartWhenEmpty="false"} Add-PnPPageWebPart -Page $page -DefaultWebPartType "QuickLinks" -Section 1 -Column 2 -Order 2 -WebPartProperties @{title="Forms";hideWePartWhenEmpty="false"} Add-PnPPageWebPart -Page $page -DefaultWebPartType "PageFields" -Section 1 -Column 2 -Order 3 -WebPartProperties @{'Property'='DateofLastMaterialChange'} # Save the changes $page.Save()