Skip to content

Commit 4cc0000

Browse files
committed
Small tweaks to keep original as discussed
1 parent be5dd1b commit 4cc0000

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

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

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Organizations often lack visibility into the volume, ownership, and status of mo
3232

3333

3434

35-
# [PnP PowerShell](#tab/pnpps)
35+
# [PnP PowerShell V2](#tab/pnpps2)
3636
```powershell
3737
3838
# ============================
@@ -143,6 +143,69 @@ catch {
143143
144144
```
145145
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
146+
147+
# [PnP PowerShell](#tab/pnpps)
148+
```powershell
149+
$siteURL = "https://domain.sharepoint.com/"
150+
$username = "username@domain.onmicrosoft.com"
151+
$password = "********"
152+
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
153+
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
154+
$dateTime = "_{0:MM_dd_yy}_{0:HH_mm_ss}" -f (Get-Date)
155+
$basePath = "E:\Contribution\PnP-Scripts\Logs\"
156+
$csvPath = $basePath + "\SitePages" + $dateTime + ".csv"
157+
$global:sitePagesCollection = @()
158+
159+
Function Login() {
160+
[cmdletbinding()]
161+
param([parameter(Mandatory = $true, ValueFromPipeline = $true)] $creds)
162+
Write-Host "Connecting to Site '$($siteURL)'" -f Yellow
163+
Connect-PnPOnline -Url $siteURL -Credential $creds
164+
Write-Host "Connection Successful" -f Green
165+
}
166+
167+
Function GetSitePagesDetails {
168+
try {
169+
Write-Host "Getting site pages information..." -ForegroundColor Yellow
170+
$sitePages = Get-PnPListItem -List "Site Pages"
171+
ForEach ($Page in $sitePages) {
172+
$sitePagesInfo = New-Object PSObject -Property ([Ordered] @{
173+
'ID' = $Page.ID
174+
'Title' = $Page.FieldValues.Title
175+
'Description' = $Page.FieldValues.Description
176+
'Page Layout Type' = $Page.FieldValues.PageLayoutType
177+
'FileRef' = $Page.FieldValues.FileRef
178+
'FileLeafRef' = $Page.FieldValues.FileLeafRef
179+
'Created' = Get-Date -Date $Page.FieldValues.Created_x0020_Date -Format "dddd MM/dd/yyyy HH:mm"
180+
'Modified' = Get-Date -Date $Page.FieldValues.Last_x0020_Modified -Format "dddd MM/dd/yyyy HH:mm"
181+
'Modified By' = $Page.FieldValues.Modified_x0020_By
182+
'Created By' = $Page.FieldValues.Created_x0020_By
183+
'Author' = $Page.FieldValues.Author.Email
184+
'Editor' = $Page.FieldValues.Editor.Email
185+
'BannerImage Url' = $Page.FieldValues.BannerImageUrl.Url
186+
'File_x0020_Type' = $Page.FieldValues.File_x0020_Type
187+
})
188+
$global:sitePagesCollection += $sitePagesInfo
189+
}
190+
}
191+
catch {
192+
Write-Host "Error in getting site pages:" $_.Exception.Message -ForegroundColor Red
193+
}
194+
Write-Host "Exporting to CSV..." -ForegroundColor Yellow
195+
$global:SitePagesCollection | Export-Csv $csvPath -NoTypeInformation -Append
196+
Write-Host "Exported to CSV successfully!" -ForegroundColor Green
197+
198+
}
199+
200+
Function StartProcessing {
201+
Login($creds);
202+
GetSitePagesDetails
203+
}
204+
205+
StartProcessing
206+
```
207+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
208+
146209
***
147210

148211
## Output

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)