Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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>
                                <FieldRef Name="Loan_x0020_Category" />
                                <Value Type="Text">Insurance:Correspondence</Value>

$query.Query = $camlquery                   

    $results = new-object System.Data.DataTable
    $results = $spsite.rootweb.GetSiteData($query) #SEEMS TO FAIL HERE

    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.

share|improve this question
I see this error when you remove the Where clause from the query. Since your code does have it, there may be some other problem. –  Nadeem Yousuf Aug 23 '13 at 7:07
Maybe you should delete whitespaces before <Where>. –  Pavel Hodek Nov 27 '13 at 9:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.