I am trying to delete recycle bin items in batches. When I try to use the SPRecycleBinItemCollectionPosition in a Do/While loop the same way I use the SPListItemCollectionPosition object, it doesn't work. The script runs through one time and quits because SPListItemCollectionPosition is always null. Is there a different syntax for the recycle bin item collection position as opposed to the list item collection position?
# build SPQuery object to get a recycle bin Items
$spQuery = New-Object Microsoft.SharePoint.SPRecycleBinQuery
$spQuery.OrderBy = "DeletedDate"
$spQuery.RowLimit = 10
$spQuery.ItemState = "FirstStageRecycleBin"
$starttime = Get-Date
write-host "Start Script at " $starttime -foregroundcolor Red
do
{
$recycledItems = $Site.GetRecycleBinItems($spQuery)
$spQuery.ItemCollectionPosition = $recycledItems.SPRecycleBinItemCollectionPosition
$ids = @()
$recycleditems | %{$ids += [GUID]$_.ID}
$recycleditems.delete($ids)
write-host "Deleted " $ids.count" items" -foreground blue
}
# do it until the item is null
while ($spQuery.ItemCollectionPosition -ne $null)
$runtime = Get-Date
write-host "Script complete at " $runtime -foreground red
Lance









