I have a classic page in SharePoint Online. It's a standard homepage from a teamsite in a classic web and I want to add a list webpart to it.
When the web is created, the Home.aspx has three webparts, a Promoted Links webpart ("Get started with your site"), a Documents webpart and a Newsfeed webpart. This is all standard.
I need to remove the Promoted Links webpart and the Documents and run this:
# Remove the Promoted Links webpart:
$wpId = (Get-PnPWebPart -ServerRelativePageUrl "$relLeafURL/SitePages/Home.aspx" -Connection $conn | Where-Object {$_.Webpart.Title -eq "Get started with your site" }).Id
Remove-PnPWebPart -ServerRelativePageUrl "$relLeafURL/SitePages/Home.aspx" -Identity $wpId -Connection $conn
# Remove the Documents webpart:
$wpId = (Get-PnPWebPart -ServerRelativePageUrl "$relLeafURL/SitePages/Home.aspx" -Connection $conn | Where-Object {$_.Webpart.Title -eq "Documents"}).Id
Remove-PnPWebPart -ServerRelativePageUrl "$relLeafURL/SitePages/Home.aspx" -Identity $wpId -Connection $conn
The two webparts are gone from Home.aspx, only the Newsfeed remains. Excellent.
Now I need to add a custom list webpart called Contacts. I get the XML from the AllItems view and add it to the page:
# Add webpart Contacts:
$webPartXml = Get-PnPWebPartXml -Identity Contacts -ServerRelativePageUrl "$relLeafURL/Lists/Contacts/AllItems.aspx" -Connection $conn
Add-PnPWebPartToWebPartPage -ServerRelativePageUrl "$relLeafURL/SitePages/Home.aspx" -XML $webPartXml -ZoneId "WPZ" -ZoneIndex 2 -Connection $conn
The webpart is indeed added to the page, but when I edit the page it's not there. Only the Newsfeed webpart which was created by default shows up. This means that I can't change any settings for the webpart, since it doesn't show in edit mode.
The webpart is listed if I run Get-PnPWebPart and also shows when I add ?contents=1 to the URL. Just not when I edit the page.
I think for some reason my webpart doesn't end up in a webpart zone, but I can't figure out how to do this. Can anyone please help?
