I have a powershell script that uses a variable $pages (containing all my publishing sites in a library) in a foreach, converts them from classic pages to modern pages and export them to a external library in a different site under the same tenant.
foreach($page in $pages)
{
Write-Host "Modernizing " $page.FieldValues["FileLeafRef"] "..."
$modernPage = ConvertTo-PnPClientSidePage -Identity $page -PublishingPage -Overwrite -TargetWebUrl https://myTenant.sharepoint.com/sites/Test/
Write-Host "Done" -ForegroundColor Green
}
It works, but the new pages does not have the same metadata as the modern site, so my idea is to manually extract the metadata from a column ("category") from the classic pages and add them to a column with the same name for the newly created site.
So in the foreach loop - for every page it will create a new page/list item in the external library (done), and also set a value for a specific column for that new list item with a value based on the specific page/classic page in the loop (not done).The new page has the same name as the classic pages and can be used to identify that specific page. Is it possible?
Example/Pseudo code would be:
Convert to modern page from $page, get the new list item with $page.name, update its column "category" from $page.category: