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 the ConvertTo-PnPPage cmdlet.
PowerShell to Convert a Classic Page to Modern Page
#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:
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
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
}
}
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.
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?
I get a lot of
ConvertTo-PnPPage : Page does not exist, any ideas?
Can you try with -CopyPageMetadata parameter?