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?

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 -UseWebLogin

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

$PagesDataColl = @()
#Collect Site Pages data
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>"  

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply