SP2010 在 CAML 查询后删除列表项



我想从我的 CAML 查询中删除列表项,但目前无法使用 foreach 循环。 在 CAML 查询后删除项目的最佳方法是什么?

$Query = New-Object Microsoft.SharePoint.SPQuery
$Query.Query = "
<Where>
<Leq>
<FieldRef Name='Created' />
<Value Type='DateTime'>
<Today OffsetDays='-30' />
</Value>
</Leq>
</Where>
<OrderBy>
<FieldRef Name='Created' Ascending='False' />
</OrderBy>"
#Get List Items matching the query
$ListItems = $oList.GetItems($Query)
write-host "Number of items retrieved:" $ListItems.Count;

foreach($ListItem in $ListItems)
{
write-host "Deleting"+ $listItem.ID + $listItem.Name + $listItem["Created"];
#$ListItem.delete();
}

请像这样删除foreach循环中的列表项:

$spweb = get-spweb http://sp/sites/devtest 
$oList = $spweb.Lists.TryGetList("List2") 
if ($oList) 
{ 
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = "
<Where>
<Leq>
<FieldRef Name='Created' />
<Value Type='DateTime'>
<Today OffsetDays='-30' />
</Value>
</Leq>
</Where>
<OrderBy>
<FieldRef Name='Created' Ascending='False' />
</OrderBy>"
$ListItems = $oList.GetItems($Query)
Write-host "Number of items retrieved:" $ListItems.Count;
foreach($item in $ListItems)
{
Write-Host "Deleting Item - $($item.Id)"
$oList.GetItemById($item.Id).delete()
}
} 

相关内容

  • 没有找到相关文章

最新更新