Skip to content

Commit b8e3787

Browse files
authored
Merge pull request #902 from ojopiyo/patch-10
Update README.md
2 parents 0ffff60 + 4cc0000 commit b8e3787

File tree

2 files changed

+156
-4
lines changed

2 files changed

+156
-4
lines changed

scripts/spo-export-all-site-pages-details/README.md

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,145 @@
44

55
## Summary
66

7-
This sample will export the required site pages information to CSV.
7+
This PowerShell script uses the PnP PowerShell module to connect to a SharePoint Online site and extract metadata from the Site Pages library. It collects key information for each page—such as titles, URLs, authorship, creation and modification dates, layout type, and banner image details—and exports the results to a timestamped CSV file for reporting and analysis purposes.
8+
9+
## Why It Matters / Real-World Scenarios
10+
11+
Organizations often lack visibility into the volume, ownership, and status of modern SharePoint pages. This script enables administrators and site owners to:
12+
- Perform content audits prior to migrations, restructures, or clean-up initiatives
13+
- Identify outdated, unused, or orphaned pages
14+
- Support governance and compliance reviews by providing page ownership and modification history
15+
- Create an inventory of pages for site redesigns or information architecture planning
16+
17+
## Benefits of the Reported Data
18+
19+
- Improved Governance: Clear visibility into who created and last modified each page
20+
- Operational Insight: Understand page usage patterns and content lifecycle
21+
- Risk Reduction: Identify pages with missing ownership or stale content
22+
- Decision Support: Enables data-driven decisions for site cleanup, archiving, or redesign
23+
- Audit Readiness: Produces a structured, exportable record of SharePoint page metadata
824

925
## Implementation
1026

1127
- Open Windows PowerShell ISE
1228
- Create a new file
1329
- Write a script as below,
1430
- First, we will connect to the site from which site we want to get Site Pages library details.
15-
- Then we will get Site Pages details and export it to CSV.
31+
- Then we will get Site Pages details and export it to CSV.
32+
33+
34+
35+
# [PnP PowerShell V2](#tab/pnpps2)
36+
```powershell
37+
38+
# ============================
39+
# Configuration
40+
# ============================
41+
$SiteUrl = "https://domain.sharepoint.com/"
42+
$BasePath = "E:\Contribution\PnP-Scripts\Logs"
43+
$DateTime = Get-Date -Format "MM_dd_yy_HH_mm_ss"
44+
$CsvPath = Join-Path $BasePath "SitePages_$DateTime.csv"
45+
46+
# Ensure log directory exists
47+
if (-not (Test-Path $BasePath)) {
48+
New-Item -ItemType Directory -Path $BasePath | Out-Null
49+
}
50+
51+
# ============================
52+
# Connect to SharePoint
53+
# ============================
54+
function Connect-ToSharePoint {
55+
param (
56+
[Parameter(Mandatory)]
57+
[string]$Url
58+
)
59+
60+
try {
61+
Write-Host "Connecting to $Url..." -ForegroundColor Yellow
62+
Connect-PnPOnline -Url $Url -Interactive
63+
Write-Host "Connected successfully!" -ForegroundColor Green
64+
}
65+
catch {
66+
throw "Failed to connect to SharePoint: $($_.Exception.Message)"
67+
}
68+
}
69+
70+
# ============================
71+
# Get Site Pages Metadata
72+
# ============================
73+
function Get-SitePagesDetails {
74+
try {
75+
Write-Host "Retrieving Site Pages..." -ForegroundColor Yellow
76+
77+
$pages = Get-PnPListItem `
78+
-List "Site Pages" `
79+
-PageSize 500 `
80+
-Fields ID,Title,Description,PageLayoutType,FileRef,FileLeafRef,
81+
Created_x0020_Date,Last_x0020_Modified,
82+
Modified_x0020_By,Created_x0020_By,
83+
Author,Editor,BannerImageUrl,File_x0020_Type
84+
85+
$results = foreach ($page in $pages) {
86+
[PSCustomObject]@{
87+
ID = $page.Id
88+
Title = $page["Title"]
89+
Description = $page["Description"]
90+
PageLayoutType = $page["PageLayoutType"]
91+
FileRef = $page["FileRef"]
92+
FileName = $page["FileLeafRef"]
93+
Created = $page["Created_x0020_Date"]
94+
Modified = $page["Last_x0020_Modified"]
95+
CreatedBy = $page["Author"]?.Email
96+
ModifiedBy = $page["Editor"]?.Email
97+
BannerImageUrl = $page["BannerImageUrl"]?.Url
98+
FileType = $page["File_x0020_Type"]
99+
}
100+
}
101+
102+
return $results
103+
}
104+
catch {
105+
throw "Error retrieving Site Pages: $($_.Exception.Message)"
106+
}
107+
}
108+
109+
# ============================
110+
# Export to CSV
111+
# ============================
112+
function Export-ToCsv {
113+
param (
114+
[Parameter(Mandatory)]
115+
[object[]]$Data,
116+
117+
[Parameter(Mandatory)]
118+
[string]$Path
119+
)
120+
121+
try {
122+
Write-Host "Exporting data to CSV..." -ForegroundColor Yellow
123+
$Data | Export-Csv -Path $Path -NoTypeInformation
124+
Write-Host "Export completed: $Path" -ForegroundColor Green
125+
}
126+
catch {
127+
throw "CSV export failed: $($_.Exception.Message)"
128+
}
129+
}
130+
131+
# ============================
132+
# Main Execution
133+
# ============================
134+
try {
135+
Connect-ToSharePoint -Url $SiteUrl
136+
$SitePages = Get-SitePagesDetails
137+
Export-ToCsv -Data $SitePages -Path $CsvPath
138+
}
139+
catch {
140+
Write-Host $_ -ForegroundColor Red
141+
}
142+
143+
144+
```
145+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
16146

17147
# [PnP PowerShell](#tab/pnpps)
18148
```powershell
@@ -75,14 +205,30 @@ Function StartProcessing {
75205
StartProcessing
76206
```
77207
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
208+
78209
***
79210

211+
## Output
212+
213+
- **Format**: CSV
214+
- **Location**: Configurable output directory
215+
- **File Naming**: Timestamped (prevents overwriting previous reports)
216+
217+
## Notes
218+
- Requires appropriate permissions to read the Site Pages library
219+
- Supports modern authentication (MFA-compatible)
220+
- Designed for single-site execution but easily extendable to multiple sites
80221

81222
## Contributors
82223

83224
| Author(s) |
84225
|-----------|
85-
| Chandani Prajapati (https://github.com/chandaniprajapati) |
226+
| [Chandani Prajapati](https://github.com/chandaniprajapati) |
227+
| [Josiah Opiyo](https://github.com/ojopiyo) |
228+
229+
*Built with a focus on automation, governance, least privilege, and clean Microsoft 365 tenants—helping M365 admins gain visibility and reduce operational risk.*
230+
231+
86232

87233
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
88234
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-export-all-site-pages-details" aria-hidden="true" />

scripts/spo-export-all-site-pages-details/assets/sample.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"This script sample shows how to export all site pages details from Site Pages library."
1010
],
1111
"creationDateTime": "2022-10-17",
12-
"updateDateTime": "2022-10-17",
12+
"updateDateTime": "2026-01-10",
1313
"products": [
1414
"SharePoint"
1515
],
@@ -36,6 +36,12 @@
3636
}
3737
],
3838
"authors": [
39+
{
40+
"gitHubAccount": "ojopiyo",
41+
"company": "",
42+
"pictureUrl": "https://github.com/ojopiyo.png",
43+
"name": "Josiah Opiyo"
44+
},
3945
{
4046
"gitHubAccount": "chandaniprajapati",
4147
"pictureUrl": "https://avatars.githubusercontent.com/u/52065929?v=4",

0 commit comments

Comments
 (0)