I am using PnP PowerShell to update the home page of a site. I would like two columns, one with a news webpart and the other column with an events webpart and a people webpart.
If I specify -Column 1
for all webparts, I get all webparts added to the page.
But if I specify that I want the news webpart in -Column 1
and the other webparts in -Column 2
, I will get an error message for the webparts that were supposed to go to the second column:
Add-PnPPageWebPart : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
+ Add-PnPPageWebPart -Page $page -Section 1 -Column 2 -Order 1 -Defau ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-PnPPageWebPart], ArgumentOutOfRangeException
+ FullyQualifiedErrorId : EXCEPTION,PnP.PowerShell.Commands.WebParts.AddWebPart
This is my code. What am I doing wrong?
$page = Get-PnPClientSidePage -Identity "Home"
$page.ClearPage()
#Add-PnPPageSection -Page "Home" -SectionTemplate OneColumnVerticalSection
Add-PnPPageSection -Page "Home" -SectionTemplate TwoColumnLeft -Order 10
Add-PnPPageWebPart -Page $page -Section 1 -Column 1 -Order 1 -DefaultWebPartType “NewsFeed” -WebPartProperties @{layoutId=”FeaturedNews”;title=”News”}
Add-PnPPageWebPart -Page $page -Section 1 -Column 2 -Order 1 -DefaultWebPartType “Events” -WebPartProperties @{layoutId=”List”;title=”Project Milestones”}
Add-PnPPageWebPart -Page $page -Section 1 -Column 2 -Order 2 -DefaultWebPartType “People” -WebPartProperties "{`"title`":`"Project Contacts`",`"persons`":[{`"id`":`"$projectManager`"}]}"