I have here a sample content. Now I want to get all the Article Template under the Folder.


I have here a code:

$query = "fast:/sitecore/content/Folder/*[@@TemplateID='{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}']" 
$items = Get-Item -Path "master:" -Query $query | Get-ChildItem -rec

But I will only query the first level under Folder (Article1, Article2, and Article5). Can someone advise me how to include in the result the Articles under the NewsFolders?


As Micheal West said, using fast query is not a recommended option. Answer for your question is

$query = "fast:/sitecore/content/Folder//*[@@TemplateID='{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}']"

use //* to get the descendants.

| improve this answer | |
  • 1
    //* is used to get the descendants. Check the query in https://[Siteurl]/sitecore/shell/default.aspx?xmlcontrol=IDE.XPath.Builder – Siva Kumar Apr 17 '19 at 6:12
  • 1
    It turns out that we need to rebuild the descendants, and I am now getting the expected results with //*. Thank you. – eudaimonia_ Apr 17 '19 at 10:20
  • 1
    @eudaimonia_ That's exactly i did few weeks back to make the fast queries working as expected.. I guess this needs to be added/updated in the answer.. – Gobinath Saminathan Apr 17 '19 at 14:59
  • 1
    You mean rebuild links database, right? I've ran into that before as well. And agreed it should be added to the answer. – jrap Apr 17 '19 at 17:53
  • 1
    @jrap exactly, it has to be added.. – Gobinath Saminathan Apr 17 '19 at 20:24

I am not sure whether this is what you need, but i tried to reproduce the scenario in my local enter image description here

and using this query i was able to get the fullpaths of all the articles under that folder

Get-ChildItem -path "/sitecore/content/Home/Articles Folder" -language * -Recurse | Where-Object { $_.TemplateName -eq 'Article' } | ForEach-Object { $_.Paths.FullPath }
| improve this answer | |

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.