Shantha Kumar T
Export the list of all SitePages details from SharePoint Site
In the fast-paced world of data management and automation, the ability to export data efficiently is a skill highly required by professionals across various fields. Fortunately, PowerShell scripts offer a powerful solution to streamline this process, allowing users to extract and manipulate data with ease.
Here’s a simple PowerShell script that assists in exporting the list of all Pages from Site Pages library from SharePoint Site with the details (Id, Title, Header, Section count, controls count, more.. ) by utilising PnP PowerShell.
PnP PowerShell version used:2.4.63-nightly
Write-Host "Execution Started..." $siteurl = "https://<tenant_name>.sharepoint.com/sites/<site_name>" Connect-PnPOnline $siteurl -Interactive $files = Get-PnPFileInFolder -Identity "SitePages" Write-Host "Total files found: "$files.length if ($files.length -gt 0) { Write-Host "Export Started..." $results = @() foreach ($file in $files) { Write-Host $file.Name if ($file.Name.Contains(".url")) { $results += [pscustomobject][ordered]@{ ID = "" Name = $file.Name Title = "" LayoutType = "" HeaderLayoutType = "" ComponentsCount = "" SectionsCount = "" Created = $file.TimeCreated LastModified = $file.TimeLastModified } } else { $page = Get-PnPPage -Identity $file.Name $results += [pscustomobject][ordered]@{ ID = $page.PageId Name = $page.Name Title = $page.PageTitle LayoutType = $page.LayoutType HeaderLayoutType = $page.PageHeader.LayoutType ComponentsCount = ($page.controls -Split ",").length SectionsCount = ($page.Sections -Split ",").length Created = $file.TimeCreated LastModified = $file.TimeLastModified } } } $results | Export-Csv -Path "allpagedetails.csv" -NoTypeInformation Write-Host "Export Completed." } Write-Host "Execution Ended."
The above script iterates to all the files from the Site Pages library and retrieve the page information. Then it exports in to the csv file in current running path.