SharePoint Online: Convert Classic Page to Modern Page using PowerShell

Requirement: Convert classic page to modern in SharePoint Online

SharePoint Online: Convert Classic Page to Modern using PowerShell

We can convert a classic page (wiki or web part page) into a modern page using ConvertTo-PnPPage cmdlet.

Convert classic page to modern in SharePoint Online

PowerShell to Convert a Classic Page to Modern Page

#Set Parameters
$ClassicPageName = "home.aspx"

#Connect to Site
Connect-PnPOnline $SiteURL -Interactive

#Convert Classic page to Modern page
ConvertTo-PnPPage -Identity $ClassicPageName -AddPageAcceptBanner

The converted page will be named as “Migrated_<pagename>.aspx”. Here is the converted page:

sharepoint online convert classic page to modern

PowerShell to Convert All Classic Pages to Modern Page

Let’s convert all pages in “Site pages” library to modern using PnP PowerShell.

#Set Parameters

#Connect to Site
Connect-PnPOnline $SiteURL -Credentials (Get-Credential)  #-Interactive

#Get All Pages from "Site Pager" Library
$Pages = Get-PnPListItem -List SitePages -PageSize 500

ForEach($Page in $Pages)
    #Get the page name
    $PageName = $Page.FieldValues.FileLeafRef
    Write-host "Converting Page:"$PageName

    #Check if the page is classic
    If($Page.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec") 
        Write-host "`tPage is already Modern:"$PageName -f Yellow 
        #Conver the classic page to modern page
        ConvertTo-PnPPage -Identity $PageName -Overwrite -TakeSourcePageName -AddPageAcceptBanner
        Write-host "`tPage Converted to Modern!" -f Green     

This PnP PowerShell script converts classic pages and renames the old files prefixed with “Previous_<pagename>” and saves the converted modern pages as source page

Please note, if your site is created with the classic site template, You have to make sure the modern site pages feature is activated. To create a modern page in classic SharePoint Online site, refer: SharePoint Online: How to Create a Modern Page in Classic Site?

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