I was wondering if it's possible to write am CAML query in SPO Online that also let's me search elements within folders in a list, so basically a recursive one.

In combination with PnP Powershell I'm able to find elements with this:

Get-PnPListItem -List $targetList -Query "<View><Query><Where><Eq><FieldRef 
Name = 'FileLeafRef'/><Value Type = 

However, this file is in the 'root' of the list. I'm not able to find test.txt if it lay in a folder.

I googled that CAML queries can have a 'scope' parameter 'query.ViewAttributes = "Scope='RecursiveAll'" that should do the trick. Unfortunately, I found no way to integrate this into PowerShell. In SharePoint 2013 it seems there's the possibility to create the query via the New-Object Microsoft.SharePoint.SPQuery class.

Any ideas or workarounds?

Thanks a lot in advance.

2 Answers 2


Try <View Scope='Recursive'>

ViewScope enumeration


Get Items Under Folder CAML

Get-PnPListItem -List $targetList -Query "<View Scope=`"RecursiveAll`"><Query><Where><Eq><FieldRef 
Name = 'FileLeafRef'/><Value Type = 

View Element

  • Thank you as well. I was able to successfully query what I intended to. Jul 13, 2017 at 6:41

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.