How to convert classic page to modern page in SharePoint Online/Office 365 using Powershell ?

Hello Sharepointers, Below are the powershell script to convert classic page to modern page in SharePoint Online/Office 365.



$pages = Get-PnPListItem -List sitepages

# Loop through over the pages
foreach($page in $pages) 
{ 
   
    if ($page.FieldValues["FileLeafRef"].StartsWith(("classicpage")))
    {
        # No need to convert modern pages 
        if ($page.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" ) 
        { 
            Write-Host 'Page $page.FieldValues["FileLeafRef"] is modern,already'
        } 
        else 
        { 
            # Create a modern version 
            Write-Host `Modernizing $page.FieldValues["FileLeafRef"]...`
            $modernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues["FileLeafRef"] -Overwrite
            Write-Host "Done" -ForegroundColor Yellow
        }
    }  
}
Happy SharePointing :-)

Leave a Reply

Your email address will not be published.