Many organizations still use classic SharePoint pages, which lack the modern responsive UI, web parts, and improved performance. Migrating to modern SharePoint pages enhances usability, accessibility, and mobile-friendliness.
In this guide, we’ll cover:
- Identifying classic pages in SharePoint.
- Converting them to modern pages using PnP PowerShell.
- Validating and customizing modern pages.
- Removing old classic pages after migration.
Step 1: Connect to SharePoint Online
Before converting pages, establish a connection to SharePoint Online using PnP PowerShell.
$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSite"
Connect-PnPOnline -Url $siteUrl -Interactive
✔ Ensures a secure connection to your SharePoint Online site.
Step 2: Identify Classic Pages for Migration
To list all classic pages, run the following command:
$classicPages = Get-PnPListItem -List "Site Pages" | Where-Object { $_["FileLeafRef"] -like "*.aspx" -and $_["ClientSideApplicationId"] -eq $null }
$classicPages | Select FileLeafRef, FileRef, Created, Modified
✔ Retrieves all classic pages (excluding modern ones).
✔ Displays file names, paths, and dates for better tracking.
Step 3: Convert Classic Pages to Modern Pages
PnP PowerShell provides a command to transform classic pages into modern ones, retaining web parts.
foreach ($page in $classicPages) {
ConvertTo-PnPClientSidePage -Identity $page["FileRef"] -Overwrite -KeepPageCreationModificationInformation
Write-Host "Converted: $($page["FileLeafRef"])"
}
✔ Converts each classic page to a modern page.
✔ Retains metadata like creation date and modified date.
Step 4: Verify Converted Modern Pages
After conversion, verify that the modern pages appear correctly.
Get-PnPListItem -List "Site Pages" | Where-Object { $_["ClientSideApplicationId"] -ne $null } | Select FileLeafRef, FileRef
✔ Ensures that the converted modern pages are listed.
Step 5: Customize Modern Pages (Optional)
1. Add Sections and Web Parts
To enhance the converted page, you can add web parts dynamically.
Add-PnPClientSideText -Page "YourModernPage.aspx" -Text "Welcome to our new modern experience!"
✔ Adds a text section to a modern page.
Add-PnPClientSideWebPart -Page "YourModernPage.aspx" -DefaultWebPartType BingMap
✔ Inserts a Bing Maps web part.
Step 6: Remove Old Classic Pages (Optional)
If migration is successful, you can delete the old classic pages.
foreach ($page in $classicPages) {
Remove-PnPListItem -List "Site Pages" -Identity $page.Id -Recycle
Write-Host "Deleted: $($page["FileLeafRef"])"
}
✔ Moves old pages to Recycle Bin (instead of permanent deletion).
Step 7: Automate the Process for Multiple Sites
If you manage multiple sites, automate the conversion for all site collections.
$siteCollections = @("https://yourtenant.sharepoint.com/sites/Site1", "https://yourtenant.sharepoint.com/sites/Site2")
foreach ($site in $siteCollections) {
Connect-PnPOnline -Url $site -Interactive
$classicPages = Get-PnPListItem -List "Site Pages" | Where-Object { $_["FileLeafRef"] -like "*.aspx" -and $_["ClientSideApplicationId"] -eq $null }
foreach ($page in $classicPages) {
ConvertTo-PnPClientSidePage -Identity $page["FileRef"] -Overwrite
Write-Host "Converted: $($page["FileLeafRef"]) on site $site"
}
}
✔ Converts classic pages across multiple sites automatically.