I have a custom list named “Expense Report” and I would like to add that in the home page as list view web part.
You can download setup files from the releases section of the PnP PowerShell repository.
Copy the below script and paste it in a notepad. Save the file as AddListViewWP.ps1.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/Flow"
- $wpTitle="Expense Report"
- $listViewURL="/sites/flow/Lists/Expense%20Report/AllItems.aspx"
- $wpPageURL="/sites/Flow/Pages/Home.aspx"
- $zoneID="Header"
- [int]$zoneIndex=1
-
- # Connect to SharePoint Online site
- Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
-
- # Get the list view webpart XML
- $xml=Get-PnPWebPartXml -ServerRelativePageUrl $listViewURL -Identity $wpTitle
-
- # Add webpart to webpart page
- Add-PnPWebPartToWebPartPage -ServerRelativePageUrl $wpPageURL -XML $xml -ZoneId $zoneID -ZoneIndex $zoneIndex
Open PowerShell window and run the following command.
folderlocation – AddListViewWP.ps1 file location
Run the following command,
Reference
Add-PnPWebPartToWebPartPage
Thus in this blog, you saw how to add list view webpart to SharePoint Online webpart page using PnP PowerShell.