Modernizing Classic And Wiki Pages In SharePoint Online

Introduction

When migrating the wiki pages from the SharePoint 2013 / SharePoint 2016 sites to SharePoint online, the pages come with a classic look and feel. The pages won’t show the option of modern site features such as ‘Apply a site template’ and ‘Site Usage’, which means the page doesn’t allow modern site design. To have a modern look and feel applied to wiki pages migrated from SharePoint on-premises environments (SP2013/SP2016), it is required to convert those pages. Fortunately, we have the PS script available from the MSFT documents.

The idea here is the script from the MSFT article, check for client-side application ID, which is getting from page values. If the page meta-data contains the application ID value b6917cb1-93a0-4b97-a84d-7cf49975d4ec, then it is a modern page, and no further action is taken. If the page meta-data does not have this client application ID property, then it applies modernization features. Please refer to the references section for more detailed information regarding the source code.

Modernizing Classic and Wiki Pages in SharePoint Online

Modernizing Classic and Wiki Pages in SharePoint Online

Challenge

The script works fine for a single site, and the script is detailed in the MSFT article, which is already mentioned in the references section. My use case is to run the modernization script for more than one site. The script from MSFT accepts the Site URL as a mandatory parameter and with some other optional parameters. The challenge I face if I am using the AS-IS script is I must run the modernization script for each site, which means if there are 10 sites, I have to run the script 10 times. Instead, what I have done, I took the same script as the input parameter and used it for-each loop, which runs the script based on the parameters loaded from a CSV.

Below is the schema for the CSV file for bulk site modernization. You can also refer to the schema from the source code attached. The file name would be ToBeModernized.csv.

Modernizing Classic and Wiki Pages in SharePoint Online

Below is the script for the Bulk Modernization,

#Add the migration account as SCA for all the sites that are getting modernized
#Get all the sites in CSV with header 'SiteURL'
#For each Site URL run the moderinization script
#Get the log written to single file
#Get the service account that has SPO admin rights
$ServiceAccount = "[email protected]"
$Creds = Get-Credential -UserName $ServiceAccount -Message "SCA admin connection to modernize and connect to spo service"
$TenantAdminUrl = "https://contosodev-admin.sharepoint.com"
Connect-SPOService -Url $TenantAdminUrl -Credential $Creds
#Path to CSV file that has sites information.
$SitesToBeModernized = Import-Csv -Path "C:\BulkSiteModernization\Input\ToBeModernized_Batch5.csv"

Foreach($siteUrl in $SitesToBeModernized.SiteURL){
    Write-Host "Starting modernization for site URL $siteUrl.." -ForegroundColor Yellow
    #Setting up the service account as site collection admin to have the necessary permissions
    Write-Host "Setting the site collection admin rights for the service account $ServiceAccount for page modernization" -ForegroundColor Yellow
    Set-SPOUser -Site $siteUrl -LoginName $ServiceAccount -IsSiteCollectionAdmin $true
    .\Convert-WikiAndWebPartPages.ps1 -SourceUrl $siteUrl -LogOutputFolder C:\BulkSiteModernization\Output -TakeSourcePageName $true -Credentials $Creds
    #revoking the sca righs for service account
    Write-Host "Revoking the site collection admin rights for the service account $ServiceAccount" -ForegroundColor Yellow
    Set-SPOUser -Site $siteUrl -LoginName $ServiceAccount -IsSiteCollectionAdmin $false
}

Step 1

Create a folder structure as shown below screenshot.

Modernizing Classic and Wiki Pages in SharePoint Online

Here ‘Modernization’ is the root folder, and Input and Output folders are created inside ‘Modernization’.

Step 2

Convert-WikiAndWebPartPages is the script from Microsoft, which can be directly downloaded from the references section and saved this file inside the ‘Modernization’ folder.

Step 3

Run the Bulk Modernization script from the same URI path, in this case, C:\Modernization.

Step 4

Validate the outputs that are written to the Output folder.

You can also download the attached script with all these files zipped for simplicity.

Conclusion

Thus, in this article, we have gone through how to modernize the classic pages migrated from SharePoint on-premises. 

References