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>
                            <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.

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

1 Answer 1

You are on the right track trying to use SPSiteDataQuery.

Remove all whitespace in the CAML. For some reason it causes issues with this class (even if it works just fine on SPQuery).

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.