Skip to content

Adds sample script to remove page header. Closes #6629 #6632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions docs/docs/sample-scripts/spo/remove-page-header/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"name": "pnp-remove-page-header",
"source": "pnp",
"title": "Remove SharePoint page header",
"url": "https://pnp.github.io/cli-microsoft365/sample-scripts/spo/remove-page-header",
"creationDateTime": "2025-03-04",
"updateDateTime": "2025-03-04",
"shortDescription": "The script removes a page header from a SharePoint page.",
"longDescription": [
"The script removes a page header from a SharePoint page."
],
"products": [
"SharePoint"
],
"categories": [],
"tags": [
"spo",
"page"
],
"metadata": [
{
"key": "CLI-FOR-MICROSOFT365",
"value": "10.5.0"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/cli-microsoft365/main/docs/docs/sample-scripts/spo/remove-page-header/assets/preview.png",
"alt": "preview image for the sample"
}
],
"authors": [
{
"gitHubAccount": "mkm17",
"pictureUrl": "https://avatars.githubusercontent.com/u/17220108?v=4",
"name": "Michał Kornet"
}
],
"references": [
{
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
"url": "https://aka.ms/cli-m365"
}
]
}
]
55 changes: 55 additions & 0 deletions docs/docs/sample-scripts/spo/remove-page-header/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
tags:
- spo
- page
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Remove SharePoint page header

The script removes a SharePoint page header.

## Disclaimer
The script will work only for pages created using the new approach for adding page headers. Headers created using the LayoutWebpartsContent property of the page will not be recognized by the script.

<Tabs>
<TabItem value="PowerShell">

```powershell
$pageName = "pagename.aspx"
$webUrl = "https://contoso.sharepoint.com/sites/example"

$m365Status = m365 status --output text
Write-Host $m365Status
if ($m365Status -eq "Logged Out") {
# Connection to Microsoft 365
m365 login
}

$controls = m365 spo page control list --webUrl $webUrl --pageName $pageName --output json | ConvertFrom-Json
$sectionIdToRemove = -1
$bannerWebpartId = "cbe7b0a9-3504-44dd-a3a3-0e5cacd07788"

foreach ($control in $controls) {
$controlPosition = $control.controlData.position

# The header section should be the first section, full-width, not a vertical section, and should contain the banner web part.
if ($controlPosition.zoneIndex -eq 1 -and $controlPosition.sectionFactor -eq 0 -and $controlPosition.layoutIndex -eq 1 -and $control.controlData.webPartId -eq $bannerWebpartId) {
$sectionIdToRemove = $controlPosition.zoneIndex
break
}
}

if ($sectionIdToRemove -ne -1) {
m365 spo page section remove --webUrl $webUrl --pageName $pageName --section $sectionIdToRemove --force
}
else {
Write-Host "No header section to remove"
}
```

</TabItem>
</Tabs>