0

how can I select only content items, items in content folder and Datasources of that items using PowerShell Extension script?

  $items = @()
    foreach($baseItem in $listOfPages) {

     if($baseItem.Paths.IsContentItem){
         
        $items += Get-Item $baseItem.Paths.FullPath
        
         foreach($childItem in Get-ChildItem $baseItem.Paths.FullPath -Recurse) {
    
            if($childItem.Paths.FullPath -contains 'Content'{
                
                Write-Host "Child items is content "
                
                $items += $childItem
            }
        }
    }
2
  • Content folder you mean /sitecore/content or any folder under an item? May 27 at 8:03
  • Yes, I mean content folder under an item only May 27 at 8:08

1 Answer 1

3

So the code will be something like this.

$items = @()

foreach($baseItem in $listOfPages) 
{
    if($baseItem.Paths.IsContentItem)
    {
        foreach($childItem in Get-ChildItem $baseItem.Paths.FullPath -Recurse) 
        {
            # Need to check that if any child item has the folder name called 'Content'
            if($childItem.Name -contains 'Content') 
            {
                Write-Host "Child items is content"
    
                # Add this item in Array         
                $items += $childItem

                # Add it's child items in Array                 
                $items += Get-ChildItem $childItem.Paths.FullPath
            }
        }
    }
}

Hope this will work.

3
  • It works, but what if the child item have the name of item itself the Content? May 27 at 8:47
  • So you need to check by the template also along with name. Because usually the content under the item is treated as a Folder template. And if you have any specific template for the content item then you can check with that. @eratosten123 May 27 at 9:56
  • @eratosten123 Did it resolve your issue? May 27 at 18:19

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.