[ ] Bug
[ ] Publishing Page Transformation: Error during the use of page transformation from PnP PowerShell when we have publishing pages with the same name in different folders
When we have multiple pages in different folders with the same name/title, the transformation engine should be able to transform them regardless their name. It should be able to transform the pages based of the pages' unique property such as ID or something else than just based of the title/name
we have folder structure in our existing publishing Pages library such as
Folder - 01 Organisation
When we run publishing page transformation using PowerShell, e.g.:
$modernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues["FileLeafRef"] -PublishingPage -ClearCache -TargetWebUrl https://tenant.sharepoint.com/sites/ModernEngineeringAdministration -PageLayoutMapping 'C:\admin\custompagelayoutmapping.xml' -LogType File -LogFolder 'C:\admin\Log' -LogVerbose -Overwrite
it will say following error when doing the transformation for introduction.aspx
ConvertTo-PnPClientSidePage : Page 'Introduction.aspx' does not exist
At line:1 char:15
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $pages[3].FieldValu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
but it will say the following for the Budget Preparation.aspx
Modernizing Budget Preparation.aspx .
Report saved as: C:\admin\Log\Page-Transformation-Report-11-04-2019-7-57-26-AM.md
if we renamed the page introduction.aspx in either Folder 01 Organisation or Folder 02 Budgets
then all pages can be transformed successfully, because they would become unique then based of their page name/title
run the publishing PowerShell transformation for this library
PS C:\Users\horzg> Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/EAClassic/Engineering_Administration
PS C:\Users\horzg> $pages = Get-PnPListItem -List pages
PS C:\Users\horzg> foreach($page in $pages)
{
# Optionally filter the pages you want to modernize
#if ($page.FieldValues["FileLeafRef"].StartsWith(("t")))
# {
# No need to convert modern pages again
if ($page.FieldValues["ClientSideApplicationId"] -eq "b6917cb1-93a0-4b97-a84d-7cf49975d4ec" )
{
Write-Host "Page " $page.FieldValues["FileLeafRef"] " is modern, no need to modernize it again"
}
else
{
# Create a modern version of this page
Write-Host "Modernizing " $page.FieldValues["FileLeafRef"] "..."
$modernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues["FileLeafRef"] -PublishingPage -ClearCache -TargetWebUrl https://tenant.sharepoint.com/sites/ModernEngineeringAdministration -PageLayoutMapping 'C:\admin\custompagelayoutmapping.xml' -LogType File -LogFolder 'C:\admin\Log' -LogVerbose -Overwrite
Write-Host "Done" -ForegroundColor Green
}
#}
}
Modernizing 02 Budgets ...
ConvertTo-PnPClientSidePage : Page '02 Budgets.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 01 Organisation ...
ConvertTo-PnPClientSidePage : Page '01 Organisation.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 04 Contractors ...
ConvertTo-PnPClientSidePage : Page '04 Contractors.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 03 Projects ...
ConvertTo-PnPClientSidePage : Page '03 Projects.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 06 Reporting ...
ConvertTo-PnPClientSidePage : Page '06 Reporting.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 05 Asset Management ...
ConvertTo-PnPClientSidePage : Page '05 Asset Management.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing 07 Miscellaneous ...
ConvertTo-PnPClientSidePage : Page '07 Miscellaneous.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing default.aspx ...
Report saved as: C:\admin\Log\Page-Transformation-Report-11-04-2019-7-43-26-AM.md
Done
Modernizing Introduction.aspx ...
ConvertTo-PnPClientSidePage : Page 'Introduction.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing Introduction.aspx ...
ConvertTo-PnPClientSidePage : Page 'Introduction.aspx' does not exist
At line:15 char:27
+ ... odernPage = ConvertTo-PnPClientSidePage -Identity $page.FieldValues[" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [ConvertTo-PnPClientSidePage], Exception
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.ClientSidePages.ConvertToClientSidePage
Done
Modernizing Off-Site Contracts.aspx ...
Report saved as: C:\admin\Log\Page-Transformation-Report-11-04-2019-7-45-33-AM.md
Done
here's some of the output from $pages
PS C:Usershorzg> $pages
Id Title GUID
-- ----- ----
2 02 Folder 3ad16fbd-173a-47e1-a2c1-22e939dbb127
3 01 Folder 612e885f-37ac-4293-92e4-3efa310fe309
4 04 Folder 3dd62101-bce0-414d-be52-3cd8c8a96dc5
5 03 Folder 4e5fc8c5-26c3-4d8a-99b5-6b62eacf1a9b
6 06 Folder ddc5785d-6feb-42c9-83d2-9cc75545eebc
7 05 Folder 6b65fc6e-cf61-4129-a68f-42006f625b95
8 07 Folder 82928adc-ec42-42ee-b663-84a172489e52
1 Engineering Administration b5335a60-a9ad-495b-9c24-65d5107c77a6
9 Engineering Cost Monitoring 140bb897-4dfd-4a06-8394-cb7616b4c8e0
10 Introduction 548b5416-ae8d-4189-8034-f6d8ece33be3
11 Introduction a108dbbc-08a4-4516-905c-2a31c9990488
12 Off-Site Contracts e6dd49cd-503c-41bc-a00b-31556b36782a
13 Approved Contractors a9b431a8-5c78-4822-94bf-de3b2615c00a
Get-PnPException : (Blank - nothing)get-module -Name SharePointPnPPowerShellOnline and copy the version info : 3.8.1904.0 Hi @berryst2
Firstly, thank you for reporting this, your feedback is valuable!
I have looked at the issue and in the ConvertTo-PnPClientSidePage there is a -Folder switch missing that can specify the folder in file resides, the FileLeafRef field value only returns the name of the file, so we need to know the path.
However, its a good point you make and we can add this as an enhancement to specify identity by ID and improve the documentation around this scenario.
Paul
Thanks @berryst2 for logging this issue. Thanks @pkbullock for the spot on answer!
If you provide the -Identity as only parameter then we'll do a query over all pages in the (site)pages library and only pick up the page if there's just one page with the given name. You can, however, use the -Folder parameter and specify a folder structure (e.g. folder1subfromfolder1). Providing the folder will 'scope' the query to only pages living inside that folder.
This is indeed a topic to be added to the FAQ in our docs.
thanks Paul & Bert for your responses!
It'd be good to know how to use the -Folder structure... in the scenario that i'm working on is that we have multiple top level folders and there could be some files with the same file name in different folders, e.g.:
Folder 1 -
File Intro.aspx
File one.aspx
Folder 2 -
File Intro.aspx
File two.aspx
Folder 3 -
File Intro.aspx
File three.aspx
how do we use the -Folder structure ? would we to specify the -Folder structure for each Folders, e,g,:
-Folder Folder 1
-Folder Folder 2
-Folder Folder 3
is there away that we could just use the parameter that will iterate through the pages library and transform the pages ?
Hi @berryst2
I was curious about the answer so wrote an example to help in this scenario, when I was testing I noticed the some small manipulation on the slashes was required in the folder path and ensuring that folders themselves aren't transformed.
In the target site, folders will be created as per above. I have tested a similar structure in my tenant so hopefully this will help you out.
See sample:
Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/EAClassic/Engineering_Administration
$pages = Get-PnPListItem -List pages
$TargetWebUrl = "https://tenant.sharepoint.com/sites/ModernEngineeringAdministration"
$PageLayoutMapping = "C:\admin\custompagelayoutmapping.xml"
$LogFolder = "C:\admin\Log"
$list = Get-PnPList "Pages"
$listRootUrl = $list.RootFolder.ServerRelativeUrl
foreach($page in $pages)
{
# Prevent folders themselves being transformed
if($page.FieldValues["FSObjType"] -eq 0){
$folder = $page.FieldValues["FileDirRef"].replace($listRootUrl, "")
if($folder -ne "/"){
$folder = $folder.TrimStart([char]'/') # If folder, then trim starting /
}
$file = $page.FieldValues["FileLeafRef"]
# Create a modern version of this page
Write-Host "Modernizing " $file "... "
$modernPage = ConvertTo-PnPClientSidePage -Identity $file -PublishingPage -ClearCache -TargetWebUrl $TargetWebUrl `
-PageLayoutMapping $PageLayoutMapping -LogType File -LogFolder $LogFolder -LogVerbose -Overwrite -Folder $folder
Write-Host "Done" -ForegroundColor Green
}
}
Thanks for the script that you've provided Paul! we've tested it and that gets around the issue. Thank you so much to you and Bert for your help!
Looks like we can close the issue. Thanks @pkbullock for the sample script, thanks @berryst2 for the verification.