I am tring to query an entire site collection for all the documents where a certain field is equal to something. For example where LoanCategory = Insurance.
I am trying to do this using an SPSiteDataQuery however I keep encountering an error that says:
The property Query contains an invalid value.
Now I have searched around and I cannot seem to find anything that is wrong with my query syntax so I am wondering if there is something else I am doing wrong. Any suggestions:
$query = new-object Microsoft.SharePoint.SPSiteDataQuery
$query.Webs = "<Webs Scope='Recursive' />"
$query.Lists = "<Lists BaseType='1' />"
$camlquery = ' <Where>
<Eq>
<FieldRef Name="Loan_x0020_Category" />
<Value Type="Text">Insurance:Correspondence</Value>
</Eq>
</Where>
'
$query.Query = $camlquery
$results = new-object System.Data.DataTable
$results = $spsite.rootweb.GetSiteData($query) #SEEMS TO FAIL HERE
$results.rows.count
foreach($row in $results.rows)
{
Write-host $row.Title
}
I am trying to avoid re-iterating through all the lists within the subwebs of this site collection doing the same query over and over. This query seemed to work when working with a caml query builder, although I have tried other queries and still no success so I am guessing it may be a problem elsewhere....
Thanks in advance.