powershell 运行Caml查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 运行Caml查询相关的知识,希望对你有一定的参考价值。
#Definition of the function that allows to do the CAML query
function DoCAMLQuery
{
param ($url,$listName)
try
{
$web = Get-SPWeb $url
$list = $web.Lists.TryGetList($listName)
if ($list)
{
$spqQuery = New-Object Microsoft.SharePoint.SPQuery
#$spqQuery.Query = "<Where><And><And><Eq><FieldRef Name='ApprovedByDepartment'></FieldRef><Value Type='Text'>109</Value></Eq><Eq><FieldRef Name='AwardFY'></FieldRef><Value Type='Text'>19</Value></Eq></And><Neq><FieldRef Name='AwardStatus' /><Value Type='Choice'>Cancelled</Value></Neq></And></Where>"
$spqQuery.Query = "<Where><Eq><FieldRef Name='AwardFY'></FieldRef><Value Type='Number'>19</Value></Eq></Where>"
#$spqQuery.ViewFields = "<FieldRef Name='FileLeafRef' /><FieldRef Name='Title' />"
#$spqQuery.ViewFieldsOnly = $true
$splListItems = $list.GetItems($spqQuery)
$iNumber=1
foreach ($splListItem in $splListItems)
{
write-host "Item # $iNumber - Name: " $splListItem.Name " ," "Title:" $splListItem["Title"] -ForegroundColor Green
$iNumber+=1
}
}
$web.Dispose()
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
Start-SPAssignment -Global
#Calling the function
$url="https://xxxx/dept/1100/CMDAWARDS/PDQStore"
$listName="Award"
DoCamlQuery -url $url -listName $listName
Stop-SPAssignment -Global
以上是关于powershell 运行Caml查询的主要内容,如果未能解决你的问题,请参考以下文章
CAML 查询未正确排序
CAML“不在”查询
CAML 查询
CAML 查询包含不起作用
SharePoint Rest Api Caml multiple condition query -Rest api 利用Caml多个条件查询
CAML查询中的自定义排序顺序