-1

I have an array of items stored in $mylist. I'm trying to check items with layout and output them. Here's the script that I have tried:

    for ($i = 0; $i -le $mylist.count; $i++) {
    $i = $mylistv| Get-Layout
    if ($i -ne $null) {
      return $i
    }
}

This is what I have tried so far, I have no idea how to exclude subitems in the final output. Any help is greatly appreciated. thank you! :)

closed as off-topic by Mark Cassidy Apr 8 at 8:49

  • This question does not appear to be about Sitecore CMS and multichannel marketing software, within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'm voting to close this question as off-topic because it isn't clear to me what the real answer is. Marek has an answer which you accepted, then commented that you updated your question. And now your question states you have a solution - but it is not related to the ticked answer. Please take some time to familiarise yourself with how the Sitecore Stack Exchange works. – Mark Cassidy Apr 8 at 8:49
1

You can try this script:

foreach ($item in $mylist) {
    $finalLayout = Get-Rendering -Item $item -FinalLayout
    if ($finalLayout -eq $null) {
        $item # this one has no layout
    }
}

or if you want to get the whole list, use

$filteredItems = $mylist | Where-Object { (Get-Rendering -Item $_ -FinalLayout) -eq $null }

It gets the final layout rendering for every item in $mylist and output those items which don't have it.

Don't use return in your loop. Otherwise you will break your loop after first match.

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