1

Have a scenario, where wanted to get list of Images which directly linked with marked page items. Below is the powerShell script which I am trying, please help

$allImages = Get-ChildItem -Path 'master:/sitecore/media library/Images' -recurse -Language * -Version *

$results = @();

[string[]]$ItemIdList = Get-Content -Path 'D:\markedItemIds.txt'

$allImages | ForEach-Object {
  $properties = @{
  Name = $_.Name
  ID = $_.ID
  Path = $_.ItemPath

  LinkedItemIds = Get-ItemReferrer -ID $_.ID | Select-Object -Property ID

  //wanted to apply condition -> LinkedItemIds matched with ItemIdList if true then get value
}

$results += New-Object psobject -Property $properties

}

$results | Select-Object -Property ID, Name, Path, LinkedItemIds
2
  • Is there a reason your marked items are in a file rather than querying for matching items directly? May 2 at 14:25
  • Hi @MichaelWest, yes there are individual Item Ids that randomly picked and listed to perform above operation. May 3 at 7:02
3

Assuming your markedItemIds.txt file contains comma separated IDs like {ID1},{ID2}, based on your powershell script I was able to filter the referrer ID's using:

$allImages = Get-ChildItem -Path 'master:/sitecore/media library/Images' -recurse -Language * -Version *

$results = @();

$ItemIdList = Get-Content -Path 'D:\markedItemIds.txt'

$allImages | ForEach-Object {
    $linkedItemIdResults = @();
    $LinkedItemIds = Get-ItemReferrer -ID $_.ID | Select-Object -Property ID

    foreach ($linkedItem in $LinkedItemIds) {
        foreach ($itemFileId in $ItemIdList.Split(",")) {
            if ($linkedItem.ID -eq $itemFileId) {
                $linkedItemIdResults += $linkedItem.ID
            }
        }
    }

    $properties = @{
       Name = $_.Name
       ID = $_.ID
       Path = $_.ItemPath
       LinkedItemIds = $linkedItemIdResults
    }

    $results += New-Object psobject -Property $properties    
}

$results | Select-Object -Property ID, Name, Path, LinkedItemIds

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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