Deleting List Items Through PowerShell

Use the following code to delete SharePoint list items through PowerShell. This code comes in handy if you have a humongous amount of data in a list and you want to delete it.

$web = Get-SPWeb http://servername/sites/sitename
$listName = "samplelist"
$list = $web.Lists[$listName]
$items = $list.Items 

Write-Host $items.Count
for($i=$items.Count-1;$i -ge 0;$i--  )
{
Write-Host $list.Items[$i].id
$list.Items[$i].Delete()
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s