SharePoint Online: Get All Site Pages using PowerShell

Requirement: Get all site pages in SharePoint Online using PowerShell.

How to Get All Site Pages in SharePoint Online using PowerShell?

If you’re a SharePoint administrator managing SharePoint Online, you’ll likely need to get a list of all the pages in a particular site, maybe for reporting purposes. This article will show you how to get all pages from a SharePoint Online site. We’ll also show you how to export pages information to Excel so that you can work with it more easily.

The easiest way to get a list of all pages on your site is to open the Site Pages library from the web browser and switch the view to “All Pages”.

sharepoint online powershell get site pages

If you need to get all site pages inventory, Let me show you how to use PowerShell to get a list of all pages in your SharePoint Online Site. Here is the PnP PowerShell script to get all pages from the “Site Pages” library and export the “Pages” data to a CSV file:

$SiteURL = ""
$CSVFile = "C:\Temp\SitePages.csv"

#Connect to PnP
Connect-PnPOnline -Url $SiteURL -Interactive

#Get All Site Pages
$SitePages = Get-PnPListItem -List "Site Pages"

$PagesDataColl = @()
#Collect Site Pages data - Title, URL and other properties
ForEach($Page in $SitePages)
    $Data = New-Object PSObject -Property ([Ordered] @{
        PageName  = $Page.FieldValues.Title
        RelativeURL = $Page.FieldValues.FileRef      
        CreatedOn = $Page.FieldValues.Created_x0020_Date
        ModifiedOn = $Page.FieldValues.Last_x0020_Modified
        Editor =  $Page.FieldValues.Editor.Email
        ID = $Page.ID
    $PagesDataColl += $Data


#Export data to CSV File
$PagesDataColl | Export-Csv -Path $CSVFile -NoTypeInformation

How to get all Modern Site Pages from the site pages library?

Well, Modern pages use the content type ID of “0x0101009D1CB255DA76424F860D91F20E6C4118001F335AF6BE6A7A43AE04581E676630ED”. So, let us apply a filter and get a list of modern pages:

#Get All Modern Site Pages
$SitePages = Get-PnPListItem -List "Site Pages" -Query "<View><Query><Where><Eq><FieldRef Name='ContentTypeId'/><Value Type='Text'>0x0101009D1CB255DA76424F860D91F20E6C4118001F335AF6BE6A7A43AE04581E676630ED</Value></Eq></Where></Query></View>"  

If you want to copy pages from one site to another, use: How to Copy Site Pages in SharePoint Online using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *