What is the Value of $spQuery when no items were returned from the filter in the query given below:

I am trying to add a conditional statement at end of this script.

if ($spQuery -eq $null){ Write-host " No results were found"}  
    $list = $web.Lists["SharePoint Site Request"]

    $spQuery = New-Object Microsoft.SharePoint.SPQuery

    $spQuery.RowLimit = 2000
    $caml = "<Where><Eq><FieldRef Name='Status' /><Value Type='Choice'>Approved/Pending</Value></Eq>
       <OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>" 
    $spQuery.Query = $caml 

I think you mean that result item collection is empty:

$itemsCollection = $list.GetItems($spQuery)
if($itemsCollection.Count -eq 0)
 Write-host " No results were found"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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