Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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()
share|improve this question
add comment

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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