2

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:

0

If you have an older version of PnP-PowerShell, you may have to perform an update, but as of the February 2019 release, ConvertTo-PnPClientSidePage supports the switch parameter -CopyPageMetadata to do exactly that without need to write any additional code to loop through metadata values.

https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/convertto-pnpclientsidepage?view=sharepoint-ps

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.