SPE now has the Merge-Layout function (similar to the one Alan Płócieniak wrote here) available out of the box. I think it's existed for about 2 years now: https://doc.sitecorepowershell.com/appendix/presentation/merge-layout.
The Merge-Layout command takes all the layout information stored in the FinalLayout field and merges into the SharedLayout field. The FinalLayout field is reset after the merge completes.
You can use it like so:
Get-Item master:"/sitecore/content/MySite/My Test Page" | Merge-Layout
or for a number of items at once:
Get-ChildItem master:\content\Showcase\int -Recurse | Merge-Layout
Also if you wish to copy back the final renderings to the page template standard values renderings field instead so then I wrote this script to do it:
function Copy-Page-FinalLayout-To-Template([string]$pagePath,[switch]$ResetLayout){
#get the page item
$item = Get-Item -Path "master:$pagePath"
#get the final layout from the page
$finalLayoutField = New-Object -TypeName "Sitecore.Data.Fields.LayoutField" -ArgumentList $Item.Fields[[Sitecore.FieldIDs]::FinalLayoutField]
if ($finalLayoutField -eq $null) {
Write-Error "Couldn't find final layout on: $($Item.Name)"
}
if ($finalLayoutField.Value -eq $null -or $finalLayoutField.Value -eq "") {
return;
}
#get the items template and standard values on the template
$template = Get-ItemTemplate -ID $item.ID
$templateItem = Get-Item -Path "master:$($template.ID)"
$templateStandardValuesPath = "$($templateItem.Paths.FullPath)/__Standard values";
$standardValuesItem = Get-Item -Path "$($templateItem.Paths.FullPath)/__Standard values"
#copy the final layout details back to the the renderings field on the standard values
$finalLayoutDefinition = [Sitecore.Layouts.LayoutDefinition]::Parse($finalLayoutField.Value)
$standardValuesItem.Editing.BeginEdit()
$standardValuesItem["__Renderings"] = $finalLayoutDefinition.ToXml();
$standardValuesItem.Editing.EndEdit()
Write-Host "Template Standard Values Updated: $($templateItem.Name)"
#reset the page final renderings back to the page templates standard values
if($ResetLayout){
Reset-ItemField -Item $Item -Name "__Final Renderings" -IncludeStandardFields
Write-Host "Page Final Renderings Reset To Standard Values: $($item.Name)"
}
}
more info here:
http://www.flux-digital.com/blog/copying-final-renderings-back-standard-values-page-templates-spe/