Dec 29, 2019

Transform Classic Page to Modern Page using PNP Powershell - SharePoint Online

Hello guys,

As the current trend is migrating on-premise versions of SharePoint to online, we definitely come across with a requirement to convert the classic sites to modern sites .

In this post i am going to show how we can transform the classic SharePoint page to modern page. There are couple of approaches to do this transformation,  like using PowerShell, .Net and SharePoint Transformation UI using ModernizationFramework .

In this post i am explaining the PowerShell method. The PnP Powershell provides a way to transform the classic SharePoint page to modern SharePoint page.

Before looking in to this code, I just wanted you to have a look of how my SharePoint Classic Page looks before transformation. Here is a sample Classic Home Page with four webparts on it.



This Classic page contains default tiles webpart with two list view and one image webpart .The layout being used here is Three Columns with Header.

Now its time to look in to the transformation PnP commands:

The prerequisite to this script is PnP Powershell module. If you don't have it already,  install it using below command .  This will install the latest PnP powershell version

Install-Module SharePointPnPPowerShellOnline

This transformation script requires a PnP Powershell 3.4 or higher . If you already have the older version and want to upgrade to latest , run the same command with '-Force' parameter .

Install-Module SharePointPnPPowerShellOnline -Force

Once we are ready with PnP, run the below script to transform the page :

Connect to the site where your page exist and convert to Modern page by giving its name ( here DevHome.aspx is the name of my classic page )

Connect-PnPOnline -Url https://mad429.sharepoint.com/ 

ConvertTo-PnPClientSidePage -Identity DevHome.aspx


Once the conversion is done, it creates a modern page with name Migrated_[Classicpagename].aspx. In this case the converted page name is Migrated_DevHome.aspx.



Below is the Converted Modern Page ( Migrated_DevHome.aspx) with the four webparts as in classic page.






If you want to keep the original name to modern page, there is a parameter called "TakeSourcePageName". This creates the modern page with the Classic Page Name and keeps the classic page name as Previous_[ClassicPage].aspx

ConvertTo-PnPClientSidePage -Identity DevHome.aspx -TakeSourcePageName

There are couple of parameters avail for this ConvertTo-PnPClientSidePage command. Here is the link from msdn where you can find complete details of this powershell approach.

Also, there is an option of giving end users to decide whether they can keep the transformed version of page or discard it. This can be done using AddPageAcceptBanner parameter to the above command and installation of PageBanner Webpart. This is still evolving topic, please refer here for more details.

If you notice the above transformation , all four webparts are transformed perfectly to modern look and feel . But this is not true for all the webparts . There are few webparts/functionalities may not supported by this transformation. So get ready with your re-design approach before jumping in to transformation.

In this post i just showed the transformation for one page . But you can write for all site pages with different parameters as per your need. Refer this Microsoft Docs Link  for more details about this  evolving topic.

Hope you like this post !