I have a Sitecore PowerShell script and I am using it to insert a rendering at a particular position on the page.
To do this, I am using the [-Index <Int32>]
parameter on the Add-Rendering
command.
Add-Rendering -Item $newItemVersion -Rendering $legacyRow -Placeholder "page-body" -FinalLayout -Index 50
You can see the full script here for more detailed look. Basically, I am looping over a number of items that all need to be updated. Each item has a parent row rendering added.
The problem I encounter is that an Index of 50 works (a number that seemed to work in my test) on one item but not for others.
On other items, the script throws an error:
Add-Rendering : Insertion index was out of range. Must be non-negative and less than or equal to size.
Does anyone know, how I properly calculate the Index parameter so that it does not exceed the maximum?