Search code examples
powershelllistviewsharepointoffice365web-parts

SharePoint Office365 Powershell Webpart AllItems.aspx


Using powershell, add webpart (image) to the list view page, e.g. AllItems.aspx.

This code is ok when I adding webpart to sitepage but what/how can do the same things in list

$mySite = Get-PnPClientSidePage -Identity "TestWP.aspx"
$jsonProp = '{
        "imageSourceType":0,
        "imageSource":"https://MMMMMM.sharepoint.com/sites/pwa/SiteAssets/img01.jpg",
        "captionText":" ",
        "altText":" ",
        "linkUrl":"",
        "overlayText":"",
        "fileName":"",
        "siteId":"",
        "webId":"",
        "listId":"",
        "uniqueId":"",
        "imgWidth":"100%",
        "imgHeight":"100%"
        }'
Add-PnPClientSideWebPart -Page $mySite -Section 1 -Column 1 -Order 1 -DefaultWebPartType Image -WebPartProperties $jsonProp

Solution

  • coffee, a little break and I got it

    first manually adding a web part to the test page then download webpart in xml format

    # get xml
    $imgWebPart = Get-PnPWebPartXml -ServerRelativePageUrl "/sites/pwa/Lists/TestList03/AllItems.aspx" -Identity "Image Viewer"
    
    Add-PnPWebPartToWebPartPage -ServerRelativePageUrl "/sites/pwa/Lists/TestList03/aa.aspx" -Xml $imgWebPart -ZoneId Main -ZoneIndex 0
    
    

    sorry for the confusion.