0

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 = 
'Text'>Test.txt</Value></Eq></Where></Query></View>"

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.

colonel_claypoo
  • 563
  • 7
  • 21

2 Answers2

4

Try <View Scope='Recursive'>

ViewScope enumeration

Example,

Get Items Under Folder CAML

Tiago Duarte
  • 5,477
  • 2
  • 21
  • 43
3
Get-PnPListItem -List $targetList -Query "<View Scope=`"RecursiveAll`"><Query><Where><Eq><FieldRef 
Name = 'FileLeafRef'/><Value Type = 
'Text'>Test.txt</Value></Eq></Where></Query></View>"

View Element

Per Jakobsen
  • 32,409
  • 1
  • 33
  • 62