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()

1 Answer 1

0

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

2
  • Thanks for the link. I didnt have patience and end up deleteting the whole list.
    – Bill Baer
    Commented Jun 14, 2012 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
    Commented Jun 14, 2012 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.