Our organisation is working on a new content structure and took a decision to do this by creating a new content tree by cloning the present one. When it was time to go live with the new content we found that when deleting the clone ID we lost a lot of information on the clone item. The only way to save the information on the fields were to break the inheritance and then delete the dependency to the master item. Doing that manually would have taken a huge amout of time on thousands of items in 16 languages. This was a great opportunity to figure out how to use the Sitecore PowerShell Extension!
It is a good idea to first set up a dev environment with production data and run the script on that environment to prevent the risk of destroying prod data. When the script is finished running, the NewHome Clone node should be disconnected from the master. Then it is easy to create a ordinary Sitecore Package of the content node and import that to the prod environment using the replace alternative.
The Sitecore setup is like the following:
This is what we would like to achieve:
The script does the following:
Now the NewHome is disconnected from the master tree!
Ok then, now we want to clean up the mess (if any).
Additional to this, the script also trim the end of the display name in case there is any blank spaces added to the end of it. This is to get a proper URL with no %20 or – at the end.
I used this script to quickly restore the dev database with production data during the development of the PowerShell script.
RESTORE DATABASE [DATABASE72Sitecore_Core] FROM DISK = N'C:\Backup\DATABASE72Sitecore_Core.bak' WITH FILE = 1, MOVE N'Sitecore.Core.Data' TO N'C:\SITE\Database\MDF\DATABASE72Sitecore.Core.MDF', MOVE N'Sitecore.Core.Log' TO N'C:\SITE\Database\LDF\DATABASE72Sitecore.Core.ldf', NOUNLOAD, REPLACE, STATS = 10 GO USE [DATABASE72Sitecore_Core] GO CREATE USER [USER72] FOR LOGIN [USER72] GO USE [DATABASE72Sitecore_Core] GO EXEC sp_addrolemember N'db_owner', N'USER72' GO RESTORE DATABASE [DATABASE72Sitecore_Master] FROM DISK = N'C:\Backup\DATABASE72Sitecore_Master.bak' WITH FILE = 1, MOVE N'Sitecore.Master.Data' TO N'C:\SITE\Database\MDF\DATABASE72Sitecore.Master.MDF', MOVE N'Sitecore.Master.Log' TO N'C:\SITE\Database\LDF\DATABASE72Sitecore.Master.ldf', NOUNLOAD, REPLACE, STATS = 10 GO USE [DATABASE72Sitecore_Master] GO CREATE USER [USER72] FOR LOGIN [USER72] GO USE [DATABASE72Sitecore_Master] GO EXEC sp_addrolemember N'db_owner', N'USER72' GO RESTORE DATABASE [DATABASE72Sitecore_Web] FROM DISK = N'C:\Backup\DATABASE72Sitecore_Core.Web' WITH FILE = 1, MOVE N'Sitecore.Web.Data' TO N'C:\SITE\Database\MDF\DATABASE72Sitecore.Web.MDF', MOVE N'Sitecore.Web.Log' TO N'C:\SITE\Database\LDF\DATABASE72Sitecore.Web.ldf', NOUNLOAD, REPLACE, STATS = 10 GO USE [DATABASE72Sitecore_Web] GO CREATE USER [USER72] FOR LOGIN [USER72] GO USE [DATABASE72Sitecore_Web] GO EXEC sp_addrolemember N'db_owner', N'USER72' GO
$rootPath = "master:\content\COMPANY\NewHome" $items = Get-ChildItem $rootPath -recurse -Version * -Language * #$items = Get-Item $rootPath -Version * -Language * ForEach ($item in $items) { $displayName = $item.DisplayName $item."__Display name" = $displayName + " " $item."__Display name" = $displayName.TrimEnd() $Title = $item.Title $item.Title = $Title + " " $item.Title = $Title $Description = $item.Description $item.Description = $Description + " " $item.Description = $Description $PromoHeader = $item.PromoHeader $item.PromoHeader = $PromoHeader + " " $item.PromoHeader = $PromoHeader $PromoText = $item.PromoText $item.PromoText = $PromoText + " " $item.PromoText = $PromoText $PromoImage = $item.PromoImage $item.PromoImage = $PromoImage + " " $item.PromoImage = $PromoImage $menuTitle = $item.MenuTitle $item.MenuTitle = $menuTitle + " " $item.MenuTitle = $menuTitle $renderings = $item.__Renderings $item.__Renderings = $renderings + " " $item.__Renderings = $renderings Reset-ItemField -Item $item -IncludeStandardFields -Name "__Source" } #$ENItem = Get-Item $rootPath -Language en $ContentPageWide = '<r xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{34EDACDD-933A-442C-9488-70B4FE891810}" /></r>' $ContentPageActiveSelected = '<r xmlns:p="p" xmlns:s="s" p:p="1"><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" s:l="{E6A2D7AC-AE27-4EBD-AA80-D594EBEEE9F1}" /></r>' $ContentPageNarrow = '<r xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{E6A2D7AC-AE27-4EBD-AA80-D594EBEEE9F1}" /></r>' $items = Get-ChildItem $rootPath -recurse -Version * -Language da-DK, de-AT, de-CH, de-DE, en-AU, en-GB, en-US, es-ES, fi-FI, fr-BE, fr-CH, fr-FR, it-IT, ko-KR, nb-NO, nl-BE, nl-NL, pt-BR, sv-SE, zh-CN #$items = Get-Item $rootPath -Language da-DK, de-AT, de-CH, de-DE, en-AU, en-GB, en-US, es-ES, fi-FI, fr-BE, fr-CH, fr-FR, it-IT, ko-KR, nb-NO, nl-BE, nl-NL, pt-BR, sv-SE, zh-CN ForEach ($item in $items) { $ENItem = Get-Item master: -ID $item.ID -Language en if($ENItem -ne $null) { if($item.DisplayName -eq $ENItem.DisplayName) { Reset-ItemField -Item $item -IncludeStandardFields -Name "__Display name" } if($item.Title -eq $ENItem.Title) { Reset-ItemField -Item $item -Name "Title" } if($item.Description -eq $ENItem.Description) { Reset-ItemField -Item $item -Name "Description" } if($item.PromoHeader -eq $ENItem.PromoHeader) { Reset-ItemField -Item $item -Name "PromoHeader" } if($item.PromoText -eq $ENItem.PromoText) { Reset-ItemField -Item $item -Name "PromoText" } #if($item.PromoImage -eq $ENItem.PromoImage) { Reset-ItemField -Item $item -Name "PromoImage" #} if($item.MenuTitle -eq $ENItem.MenuTitle) { Reset-ItemField -Item $item -Name "MenuTitle" } $itemRenderings = $item.__Renderings $ENitemRenderings = $ENitem.__Renderings if($itemRenderings -ne $ENitemRenderings) { if($ENitemRenderings -ne $ContentPageWide -and $ENitemRenderings -ne $ContentPageNarrow -and $ENitemRenderings -ne $ContentPageActiveSelected) { Reset-ItemField -Item $item -IncludeStandardFields -Name "__Renderings" } } } }
After successfully running the script I cleaned up the Renderings field on the language versions in case the renderings were the same as for the EN version.
$rootPath = "master:\content\COMPANY\NewHome" $ContentPageWide = '<r xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{34EDACDD-933A-442C-9488-70B4FE891810}" /></r>' $ContentPageActiveSelected = '<r xmlns:p="p" xmlns:s="s" p:p="1"><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" s:l="{E6A2D7AC-AE27-4EBD-AA80-D594EBEEE9F1}" /></r>' $ContentPageNarrow = '<r xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><d id="{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}" l="{E6A2D7AC-AE27-4EBD-AA80-D594EBEEE9F1}" /></r>' $items = Get-ChildItem $rootPath -recurse -Version * -Language da-DK, de-AT, de-CH, de-DE, en-AU, en-GB, en-US, es-ES, fi-FI, fr-BE, fr-CH, fr-FR, it-IT, ko-KR, nb-NO, nl-BE, nl-NL, pt-BR, sv-SE, zh-CN ForEach ($item in $items) { $ENItem = Get-Item master: -ID $item.ID -Language en if($ENItem -ne $null) { $itemRenderings = $item.__Renderings $ENitemRenderings = $ENitem.__Renderings if($itemRenderings -eq $ENitemRenderings) { Reset-ItemField -Item $item -IncludeStandardFields -Name "__Renderings" } } }
The policy on our computer at work is that the Windows Login Screen shows up after a couple of minutes in case of user being inactive. Running the script and not working on the computer at the same time may cause the lock screen to show up and then the script may stop running in the background. I search for a solution on hacking the registry or local policy but the easiest way not conflicting with the companys policy (there is a reason for policies…) is to start the Windows Media Player, choose any music and run it using the repeat function. Then the lock screen will not appear and the PowerShell script may run util it is done! In my case it took about 5 hours…
RRS feed