0

I need to copy item field data from en language to all other available languagesin all versions. Any powershell script of achieving this.

3
  • @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
    Commented Aug 22, 2020 at 19:10
  • I just want to clarify that the Add-ItemLanguage command does copy existing values. You can configure if you do not want this with the -DoNotCopyFields flag. Additionally, you can specify which fields you do not want to have copied by using -IgnoredFields
    – Koen Heye
    Commented Jul 28, 2021 at 15:16

1 Answer 1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.