We got duplicate dynamic placeholders assigned in Final Layout. How can I remove the duplicates from the Final Layouts in all the languages?

This is how we are filtering out the placeholders matching the regex. In $matches we get the collection of all the dynamic placeholders, the next step is to remove the duplicates and I want to avoid the nested looping to check and delete:

Get-Rendering -Item $_ | ForEach-Object {
    $rendering = $_;
    $matches = [regex]::Matches($_.Placeholder,'(-{[0-9a-fA-F]{8}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{12}}-0)')

    if ($matches.Success) {
        $newPlaceholder = $rendering.Placeholder

        $matches | ForEach-Object {
            $renderingId = $_.Value

enter image description here

  • How can you tell they are duplicate?
    – Richard Seal
    Jun 12, 2019 at 21:33
  • If we look at the ItemID assigned, those are repeating after five and we see duplicate items on the page as well. Jun 12, 2019 at 21:35
  • What if there was another component mingled between the videos? How would you have known? Perhaps you know because the datasource is the same? Jun 12, 2019 at 23:37
  • Correct Mike. We verified the data source is same for all duplicates. Also as I said same video is displaying twice in the right rail on the page. Jun 13, 2019 at 0:04

1 Answer 1


Firstly, you can filter the renderings returned before you get to a ForEach-Object, by using a Where-Object (my regex skills are limited, so I've just copied yours):

$Renderings =  Get-Rendering -Item $CurrentItem -FinalLayout | Where-Object {$_.Placeholder -match '(-{[0-9a-fA-F]{8}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{4}[-][0-9a-fA-F]{12}}-0)'}

Then you can build an array of your duplicate criteria (in your case the combination of placeholder and datasource). If a value is already in the array, you can remove the rendering.

$UniqueValues = @()
$Renderings | ForEach-Object{
    $Identifier = -join($_.Datasource, $_.Placeholder)
        If($UniqueValues -Contains $Identifier){
            Remove-Rendering -Item $CurrentItem -Instance $_

            $UniqueValues ,+= $Identifier


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.