Wednesday, August 21, 2013

Query SharePoint Choice Field List Items using CAML

Below script gets list items where 'Address Type' not equal to ‘Home Address’ of choice field

Start-SPAssignment
-Global
$url = "YoursiteURL"
$web = get-spweb $url

$list=$web.Lists["EmployeeDocuments"]
Write-Host $list.title
$i=1

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery ="<Where><Neq><FieldRef Name='Address_x0020_Type'/><Value Type='Choice'>Home Address</Value></Neq></Where>"
$spQuery.Query = $camlQuery
$spQuery.ViewAttributes = "Scope=Recursive";
$spListItems = $list.GetItems($spQuery)
     
Write-Host "count" $spListItems.count
     
#    foreach ($item in $spListItems)
#           {
#                 write-host $i  $item["Address Type"]
#                
#                 $i++
#           }


 Stop-SPAssignment -Global



No comments:

Post a Comment

Followers