How can I add webpart using Powershell script in SharePoint online modern page?
Add Webpart using PowerShell script, I tried many more times to do that but got errors and warnings. can you help me solve that issue?
You need to use the command Add-PnPPageWebPart from the PowerShell module Pnp.PowerShell
Sample of code:
$siteUrl = "https://my-tenant.sharepoit.com/sites/my-site"
Connect-PnPOnline -Url $siteUrl -Interactive
$pageUrl = "home.aspx"
$page = Get-PnPPage -Identity $pageUrl
Add-PnPPageTextPart -Page $page -Text "Hello world!"
Add-PnPPageWebPart -Page $page -DefaultWebPartType "List" -WebPartProperties @{ webRelativeListUrl = "/SitePages"}
Console:
Result:
What is your problem?
What kind of errors do you have?