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 on 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 page 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:

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$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      
        CreatedBy = $Page.FieldValues.Created_x0020_By
        CreatedOn = $Page.FieldValues.Created
        ModifiedOn = $Page.FieldValues.Modified
        ModifiedBy =  $Page.FieldValues.Editor.Email
        ID = $Page.ID
        PromotedState = $Page.FieldValues.PromotedState
        Title = $Page.FieldValues.Title
        PageLayout = $Page.FieldValues.PageLayoutType
    })
    $PagesDataColl += $Data
}
 
$PagesDataColl

#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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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