I need to copy item field data from en language to all other available languagesin all versions. Any powershell script of achieving this.
-
doc.sitecorepowershell.com/working-with-items/item-languages – Michael West Aug 22 '20 at 19:01
-
@MichaelWest these script create a new version doesn't copy value to existing version. I am looking for something that copy value to existing version – kartik Aug 22 '20 at 19:10
Probably the below script can help you. The comments are added to the script to make each step obvious. You can do modifications to it to suit your purpose -
#Get all language versions defined in System/Languages
$languages = Get-ChildItem /sitecore/System/Languages -recurse | Select $_.name | Where-Object {$_.name -ne "en"} | Select Name
#Ensuring correct items are updated by comparing the template ID
$items = Get-ChildItem -Path "/sitecore/<your item location>" -Recurse | Where-Object {'<item template id>' -contains $_.TemplateID}
#Bulk update context to improve performance
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) {
foreach($item in $items){
foreach($language in $languages){
$languageVersion = Get-Item -Path $item.Paths.Path -Language $language.Name
#Check if language version already exists
if($languageVersion -eq $null){
Write-Host "Creating "$language.Name" version for "$item.Name
Add-ItemLanguage -Item $item -Language "en" -TargetLanguage $language.Name -IfExist OverwriteLatest
}
}
}
}
The script is also available at my blog.