1

In a SP Online page, there are multiple sections with webparts on them. I want to totally clear them with PnP PowerShell.

So far I have

Connect-PnPOnline -Url "https://abc.sharepoint.com/sites/TestSite" -Interactive
write-host "Removing zones from home page..."

$pg = Get-PnPPage -Identity "Home"
$sectionsCount = $pg.Sections.Count
write-host "Found $($sectionsCount) zones"
for($i=$sectionsCount-1; $i -ge 0; $i--) {
    write-host "Removing zone $($i)"
    $pg.Sections.RemoveAt($i)
}
$page = Set-PnPPage -Identity $pg -Publish

When I run this, it sees the number of zones and iterates through them. But after it runs, when I refresh the page, all the sections are still there.

I am on latest version 1.7.0 PnP.PowerShell.

Does anyone know what's wrong?

5
  • 1
    Have you tried applying page template?
    – jo1storm
    Commented Sep 15, 2021 at 14:54
  • No, what is that?
    – omega
    Commented Sep 15, 2021 at 14:56
  • 1
    After connecting to site, you can do Get-PnPSiteTemplate to export the page template of the home page of the site you are on. Then you can do Invoke-PnPSiteTemplate. If you delete everything from the first page, then export, it should get deleted on the imported site. See here for use docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/…
    – jo1storm
    Commented Sep 15, 2021 at 15:04
  • That actually worked, thanks.
    – omega
    Commented Sep 15, 2021 at 15:10
  • Nice. Please accept the answer then.
    – jo1storm
    Commented Sep 16, 2021 at 7:16

1 Answer 1

0

After connecting to site, you can do Get-PnPSiteTemplate to export the page template of the home page of the site you are on. Then you can do Invoke-PnPSiteTemplate.

If you delete everything from the first page, then export, it should get deleted on the imported site. See here for use:

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/invoke-pnpsitetemplate?view=sharepoint-ps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.