4

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.

2
  • 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. Commented Aug 23, 2013 at 7:07
  • Maybe you should delete whitespaces before <Where>. Commented Nov 27, 2013 at 9:06

2 Answers 2

2

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

2

Start working when i change $camlquery.

From:

$camlquery =    '   <Where>
                            <Eq>
                                <FieldRef Name="Loan_x0020_Category" />
                                <Value Type="Text">Insurance:Correspondence</Value>
                            </Eq>
                        </Where>
                    '

To:

$camlquery =    '<Where><Eq><FieldRef Name="Loan_x0020_Category" /><Value Type="Text">Insurance:Correspondence</Value></Eq></Where>'

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.