Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

SPRecycleBinItemCollectionPosition always null when trying to empty recycle bin in batches (powershell)

$
0
0

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


Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>