In 2 steps convert a classic SharePoint page to modern using PnP

No comments

 19,476 total views,  140 views today

Over the many years we as a SharePoint professional, we have been using the SharePoint classic page both in SharePoint on-premise and SharePoint online(classic). But recently in the last couple of years, Microsoft has been focusing to convert the classic SharePoint to modern SharePoint. So in this article, we will learn about how to convert a classic SharePoint page to a modern page in 2 steps using PnP PowerShell.

However, before that, we will learn about what is a classic page in SharePoint online, what is the modern page in SharePoint online, what is the difference between classic and modern pages in SharePoint and finally we will learn about how to convert the classic SharePoint site to modern.

Table of Contents:

  • What is a classic page in SharePoint online?
  • What is the modern page in SharePoint online?
  • Example of SharePoint online classic page
  • Example of SharePoint online modern home page
  • Convert a classic SharePoint site to modern page
  • Install PnP PowerShell in SharePoint online
  • Convert classic SharePoint site page to modern page – PnP script
  • ConvertTo-PnPClientSidePage command – examples

What is a classic page in SharePoint online?

The traditional way or standard way of working with SharePoint pages is the classic SharePoint page where we will have a web part page – and there easily we can add a new web part to the page, not only web part page, we have many more classic pages as below:

  • Wiki page
  • Web part page
  • Blog page
  • Publishing page

These pages have a predefined placeholder to add our own content to SharePoint as per our needs.

Example of SharePoint online classic page:

Example of classic webpart page: SharePoint online classic page
SharePoint online classic page

What is the modern page in SharePoint online?

On the other hand, the modern site pages are a new development from Microsoft, which is very fast and support rich multimedia content. Modern pages look great on any device which gives the high portability to the page, In modern site pages, we add a rich multimedia web part as a video, images, list, and libraries to design a page. In modern pages very easily we connect parent, child web part to a page which renders dynamically.  The modern pages, also give us the flexibility to add a dynamic layout. We can add as many sections as we need to align our content and web part as per our needs.

Example of SharePoint online modern home page:

Example of modern home page: SharePoint online modern page
SharePoint Online modern page

Convert a classic SharePoint site to a modern page:

This is my classic site home page, we will convert this page to modern page in SharePoint online, using the PnP PowerShell in the upcoming steps.

Classic home.aspx page: sharepoint online classic home page
SharePoint online classic home page

Install PnP PowerShell in SharePoint online:

In order to execute the PnP PowerShell in SharePoint online, we need to install the PnP PowerShell in SharePoint Online. For the installation, please refer my previous article Office 365: Getting started with SharePoint PnP PowerShell – installation

Convert a classic SharePoint site page to modern page – PnP script:

Using the below code we can convert the classic SharePoint site page to modern page:

############################Description#######################################################
#The below script will convert the classic SharePoint page to modern SharePoint page using PnP
##############################################################################################

CLS
$userName = "Global-sharepoint2019@globalsharepoint2019.onmicrosoft.com"
$passWord = "YourSPOPassWord"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord

Connect-PnPOnline -Url "https://globalsharepoint2019.sharepoint.com/sites/SharePointRNDClassic" -Credentials $cred
 
#Using the below command converting the classic "home.aspx" page to modern page and adds the page accept banner web part on top of the page.  
ConvertTo-PnPClientSidePage -Identity home.aspx -AddPageAcceptBanner  

Note:

Convert classic SharePoint site page to modern page: execution

Script execution: Convert classic sharepoint site page to modern page
Convert classic SharePoint site page to modern page

In the above PowerShell console, we can see that the “home.aspx” has successfully converted as “Migrated_Home.aspx”

Now, let’s go back to our SharePoint online site. Now we can nothing has been changed to the SharePoint home page – the reason is being, still in the URL we can see the “Home.aspx”, we need to change this page to “Migrated_Home.aspx” page in the URL. In the next step, we will see how?

home.aspx classic page to modern page: Convert classic SharePoint site page to modern page
Convert classic SharePoint site page to modern page

Go to the “Site Pages” library -> select “Migrated_Home.aspx” ->click on “Make homepage”

Set as make home page: Convert classic sharepoint site page to modern page
Convert classic SharePoint site page to modern page

Now again, let’s navigate to the same SharePoint site home page, now we can see that the home page has been converted to the modern home page as in the URL – we see the new migrated page, i.e “Migrated_Home.aspx”

Migrated_home.aspx page: Convert classic SharePoint site page to modern page
Convert classic SharePoint site page to modern page

Using the below PnP PowerShell script, we can convert all classic SharePoint pages to modern pages from the “Site Pages” library.

############################Description#######################################################
#The below script will convert the classic SharePoint page to modern SharePoint page using PnP
##############################################################################################

CLS
$userName = "Global-sharepoint2019@globalsharepoint2019.onmicrosoft.com"
$passWord = "YourSPOPassWord"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord

Connect-PnPOnline -Url "https://globalsharepoint2019.sharepoint.com/sites/SharePointRNDClassic" -Credentials $cred
 
#Using the below command converting the classic "home.aspx" page to modern page and adds the page accept banner web part on top of the page.  
#ConvertTo-PnPClientSidePage -Identity home.aspx -AddPageAcceptBanner

#########The below code will convert all classic pages from the "Site Pages" libray to modern page#######
# Get all the pages in the site pages library  
$pagesInSitePagesLibrary = Get-PnPListItem -List "sitepages"  
 
#Loop thru the sites pages library.  
foreach($onePage in $pagesInSitePagesLibrary)   
{   
    #Optionally filter the pages you want to modernize
    if ($page.FieldValues["FileLeafRef"].StartsWith(("t")))
    {
       $moderNPage= Get-PnPClientSidePage -Identity $onePage.ID
        #If the page is already modern - no need to convert it.
        if ($onePage.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec")   
        {   
                        
            Write-Host "Page " $onePage.FieldValues["FileLeafRef"] " is already modern, so no need to modernize it again"   
        }   
        else   
        {   
            #Converting to modern page
            Write-Host `Converting to modern page $onePage.FieldValues["FileLeafRef"]..........`  
            $modernConvertedPage = ConvertTo-PnPClientSidePage -Identity $onePage.FieldValues["FileLeafRef"] -Overwrite 
            Write-Host "Page " $onePage.FieldValues["FileLeafRef"] " has been successfully converted to modern page" -ForegroundColor Green 
        }  

    }
        
}  

#######convert all classic pages from the "Site Pages" libray to modern page - ends here################# 

 

ConvertTo-PnPClientSidePage command – examples:

Converts wiki page to SharePoint online modern page with the given XML file:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Overwrite -WebPartMappingFile "c:\temp\webpartmapping.xml"

 

The above command converts a wiki page named ‘somepage’ to a client-side page using a custom provided mapping file. 

Converts wiki page to SharePoint online modern page with the “AddPageAcceptBanner”.

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Overwrite -AddPageAcceptBanner

 

The above command converts a wiki page named ‘somepage’ to a client-side page and adds the page accept banner web part on top of the page. This requires that the SPFx solution holding the web part has been installed to the tenant app catalog.

Converts wiki page to SharePoint online modern page along with the page metadata:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Overwrite -CopyPageMetadata

 

The above command converts a wiki page named ‘somepage’ to a client-side page, including the copying of the page metadata (if any).

Converts publishing page to SharePoint online modern page in the specific target site URL:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -PublishingPage -Overwrite -TargetWebUrl https://globalsharepoint2019.sharepoint.com/sites/targetmodernsite

 

The above command converts a publishing page named ‘somepage’ to a client-side page in the globalsharepoint2019.sharepoint.com/sites/targetmodernsite site.

Converts publishing page to SharePoint online modern page in the specific “TargetConnection”, from one tenant to another tenant.

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -PublishingPage -Overwrite -TargetConnection $target

 

The above command converts a publishing page named ‘somepage’ to a client-side page in the site specified by the TargetConnection connection. This allows to read a page in one environment (on-premises, tenant A) and create in another online location (tenant B)

Converts web part page to SharePoint online modern page in the specific library and folder:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Library "SiteAssets" -Folder "Folder1" -Overwrite

 

The above command converts a web part page named ‘somepage’ living inside the “SiteAssets” library in a folder named “Folder1” into a client-side page.
Converts web part page to SharePoint online modern page – root of the site collection:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Folder "<root>" -Overwrite

 

The above command converts a web part page named ‘somepage’ living inside the root of the site collection (so outside of a library).

Converts wiki page to SharePoint online modern page in the specific target site URL:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -Overwrite -TargetWebUrl https://globalsharepoint2019.sharepoint.com/sites/targetmodernsite

 

Converts a wiki page named ‘somepage’ to a client-side page in the https://globalsharepoint2019.sharepoint.com/sites/targetmodernsite site

Convert the web part page to SharePoint online modern page with the log file.

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -LogType File -LogFolder c:\temp -LogVerbose -Overwrite

 

The above command converts a web part page named ‘somepage’ and creates a log file in “c: \temp” using verbose logging

Convert web part page to SharePoint online modern page with the log file but skip the actual write:

ConvertTo-PnPClientSidePage -Identity "somepage.aspx" -LogType SharePoint -LogSkipFlush

 

Converts a web part page named ‘somepage’ and creates a log file in SharePoint but skip the actual write. Use this option to make multiple ConvertTo-PnPClientSidePage invocations create a single log.

Summary:

Thus, in this article we have learned the below topics with respect to converting the classic SharePoint page to modern page:

  • What is the classic page in SharePoint online?
  • What is the modern page in SharePoint online?
  • Example of SharePoint online classic page
  • Example of SharePoint online modern home page
  • Convert classic SharePoint site to modern page
  • Install PnP PowerShell in SharePoint online
  • Convert classic SharePoint site page to modern page – PnP script
  • ConvertTo-PnPClientSidePage command – examples:

See Also:

Reference URL:

Free download SharePoint Online & Office 365 Administration eBook(238 Pages)

Get the PDF eBook from here:


[purchase_link id="0" style="button" color="blue" text="Free Download SharePoint Online & Office 365 Administration"]

 

 
FREE DOWNLOAD

Send download link to:

Subscribe to get exclusive content and recommendations every month. You can unsubscribe anytime.