2
votes

I have a requirement to replace a load (2000+) images within the Sitecore media library with optimised images with the same name. I need to keep the original GUIDS so that all images are still linked.

So I basically need to replace the image blob data and size data. I have written a powershell script to do this however I have found it consistently will all process 100 items. I can not see any reason for this, it could just be my script is rubbish as i haven't used powershell much before.

$CurrentImages = Get-Item  -Path master: -Query '/sitecore/media library/Images/Products//*[@@TemplateName="Jpeg"]';


$NewImages = Get-Item  -Path master: -Query '/sitecore/media library/NewImages//*[@@TemplateName="Jpeg"]';

Write-Host $NewImages.Count;


$CurrentImages|foreach{ $Current = $_;  $NewImages|foreach{ $New = $_; if($New.DisplayName -eq $Current.DisplayName){ Write-Host $Current.DisplayName; $Current.Blob = $New.Blob; $Current.Size = $New.Size; $New | Remove-Item}}};

Im using the sitecore powershell extention if that also helps

1

1 Answers

12
votes

The limit is actually imposed on the query mechanism by the CMS in Sitecore.config. You can find the following line, and change it to up the limit:

<setting name="Query.MaxItems" value="100" />

However I would suggest that in case of larger searches you might want to use the Find-Item cmdlet that utilizes the Sitecore Content Search infrastructure.

You can find more different strategies to locate content in the Gist I've put together some time ago with performance analysis.

In case of Find-Item however you will want to pipe your search results into Initialize-Item to turn the Search result items into full sitecore items.

Edit: As learned on the Slack schannel (Thanks Kamruz Jaman!) This limit is further augmented in Sitecore 8.1 in App_Config\Include\Sitecore.ExperienceExplorer.config to 260, but clearly in your case the first limit is still the case.

<setting name="Query.MaxItems">
    <patch:attribute name="value">260</patch:attribute>
</setting>