1

I would like to know how to get all related media id's from page using Sitecore PowerShell module and create new language definition for media items.

So we have a page that have image field in data source, I would like to know how to gather all image field and media items, and for each selected to create new language version.

2 Answers 2

1

You can achieve this functionality using the below steps. I don't have ready script but I can guide you:

  1. You need to get all items in Recurse mode and need to apply ForEach loop like below code:
$allItems = Get-ChildItem -Path 'master://sitecore/content/home' -Recurse
$allItems | ForEach-Object {
    
}
    
  1. In this loop you need to get all image fields in the current item as well as in datasource using Get-ItemField command. More details are here

  2. After that you can create new version of media item using this command Add-ItemVersion. Link are here

1

You can use this approach and modify it as per your need.

$item =  Get-Item -Path "master:" -Uri "sitecore://master/{5003FB09-4ADF-410C-9F93-03EDF2FC137F}?lang=en-us&ver=1" # Get the Item here.

$imageFields = $item.Fields | where {$_.Type -eq 'Image'} # Get all the fields of type Image

# Create Loop on all fields 

ForEach ($imageField in $imageFields ) 
{  
     [Sitecore.Data.Fields.ImageField] $field = $imageField  # Cast into ImageField

     $imageItem = $newitem = Get-Item -Path master: -ID $field.mediaID   # Get Image Item from mediaID

     Add-ItemLanguage -Item $imageItem -Language "en-US" -TargetLanguage "en" -IfExist OverwriteLatest # Create Languaeg Version                    
}
0

Your Answer

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