Posts

Showing posts from September, 2018

Change layout Sitecore Powershell Extensions script

Today I got a request to update thousands of items' layouts. The requirement arose because the solution was using around 6 layouts and we all know that a good practice is to have the least number of layouts possible (1 per device is recommended). We ended up combining those layouts and we needed to update the presentation details of the existing items.

In order to do this, I created the following SPE script which updates all the items' layouts starting from the specified root path: 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20$rootItem = Get-Item -Path master:"PATH TO ROOT"$newLayout = Get-Item -Path master:"NEW LAYOUT PATH"$oldLayout = Get-Item -Path master:"OLD LAYOUT PATH"$defaultDevice = Get-LayoutDevice"Default"# True: Update Final Layout - False: Update Shared Layout$useFinalLayout = $False# True: Informative only - False: Update Items$reportOnly = $Falseforeach ( $iteminGet-ChildItem -Item $rootItem -Recurse ) { …

Update Placeholder Settings using Sitecore Powershell Extensions

The following SPE script helps to update the Placeholder Settings of Sitecore items:


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26$rootItem = Get-Item -Path master:/sitecore/content/Cerner $oldPlaceholderSettingItem = Get-Item -Path master:"/sitecore/layout/Placeholder Settings/Careers/careers-header"$newPLaceholderSettingItem = Get-Item -Path master:"/sitecore/layout/Placeholder Settings/Careers/Structure/Header"$reportOnly = $Falseforeach($pageinGet-ChildItem -Item $rootItem -Recurse){ #Only items with a layoutif (Get-Layout$page) { $oldRenderings = $page.__Renderings if($oldRenderings-like$oldPlaceholderSettingItem.Key){ #Replace Path$newRenderings = $oldRenderings.Replace($oldPlaceholderSettingItem.FullPath, $newPLaceholderSettingItem.FullPath) #Replace Key$updatedRenderings = $newRenderings.Replace(($oldPlaceholderSettingItem.Name), $newPLaceholderSettingItem.Name)������������������…