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

The Modern pages are the new standard for SharePoint and offer a number of advantages over classic pages, including improved performance, an intuitive user interface, and support for responsive design. In this blog post, we’ll provide a step-by-step guide on how to convert a classic page to a modern page in SharePoint Online.

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

Convert classic page to modern in SharePoint Online

PowerShell to Convert a Classic Page to Modern Page

To transform a classic page to a modern page, use this PowerShell script. Make sure the “Site Pages” feature is activated in the classic sites before using this script.

#Set Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"
$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 the “Site pages” library to modern using PnP PowerShell.

#Set Parameters
$SiteURL="https://crescent.sharepoint.com/sites/marketing"

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

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

Try {
    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 
        }
        Else
        {
            #Conver the classic page to modern page
            ConvertTo-PnPPage -Identity $PageName -Overwrite -TakeSourcePageName -AddPageAcceptBanner
            Write-host "`tPage Converted to Modern!" -f Green     
        }
    }
}
Catch {
    write-host -f Red "Error Converting Clasic Page to Modern!" $_.Exception.Message
}

This PnP PowerShell script converts classic pages, renames the old files prefixed with “Previous_<pagename>,” and saves the converted modern pages as the source page so that it doesn’t end up with any broken links.

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 on a classic SharePoint Online site, refer: SharePoint Online: How to Create a Modern Page in Classic Site?

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!

6 thoughts on “SharePoint Online: Convert Classic Page to Modern Page using PowerShell

  • How about a try / catch for when a page hangs and there’s a non-terminating error, so a timeout value of say 3 minutes and then continue noting page did not convert successfully due to timeout.

    Reply
  • Getting the same page does not exist error with or without the -CopyPageMetadata parameter

    Reply
    • If your pages are outside the “Site Pages” library, use: -Library ‘Library-url'” or -Folder ‘Folder-URL’ parameters.

      Reply
  • I get a lot of
    ConvertTo-PnPPage : Page does not exist, any ideas?

    Reply

Leave a Reply

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