0

A truncate would really help cause for each delete loop will take for ever. I am trying to delete 500k records and it's very slow. It's taking 3 minutes to delete 1 record.

# Delete items from a list
if((Get-PSSnapin | Where {$_.Name -eq “Microsoft.SharePoint.PowerShell”}) -eq $null)
{
    Add-PSSnapin Microsoft.SharePoint.PowerShell
}

$web = Get-SPWeb http://portal.logix.com/billing

# IMPORTANT - LIST NAME IS DIPLAY NAME NOT INTERNAL NAME
$list=$web.Lists["Sales Tickets"]

$listItems = $list.Items
$listItemsTotal = $listItems.Count

for ($x=$listItemsTotal-1;$x -ge 0; $x--)
{ 
    # USE THIS IF YOU HAVE CONDITION
    #if($listItems[$x].name.Contains("3")) 
    #{ 
    Write-Host("DELETED: " + $listItems[$x].name)
    $listItems[$x].Delete()
    #} 
}
$web.Dispose()
Bill Baer
  • 395
  • 5
  • 15

1 Answers1

0

By all reports, using ProcessBatchData is considerably faster, as detailed here

Dave Wise
  • 13,181
  • 18
  • 19
  • Thanks for the link. I didnt have patience and end up deleteting the whole list. – Bill Baer Jun 14 '12 at 16:57
  • That works too as long as you don't have any external dependencies on the content, like Lookup Columns or Content Query Web Parts, List View Web Parts, etc., as those will break if the list is deleted. – Dave Wise Jun 14 '12 at 17:14