Quick Powershell to delete all items in my Sharepoint list

Standard

A quick post with a simple script I gathered a while back that comes in handy for data cleansing before releasing a site:
– how to delete the 100s of items in my list without doing it from the web interface (limited to the maximum displayed in a view)

Use the #powershell script below.

Warning: do this at your own risk, don’t get the wrong site/list or you will regret it ;-)

Save this into a DeleteAll.ps1 file
replace “http://SharepointSite” by your site and “ListName2 by the list name where to delete all items.
and run .\DeleteAll.ps1 from Sharepoit PowerShell cmd prompt.
<strong>
</strong>&nbsp;# script starts here…</div>
<div>[System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”) | out-null
$oContentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService;
[Microsoft.SharePoint.Administration.SPWebApplicationCollection]$waColl = $oContentService.WebApplications;
$siteUrl = “http://SharepointSite”
$webName = “”
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb($webName)
$spList = $spWeb.Lists["List Name"]
foreach ($item in $spList.items)
{
$deaditem=$splist.GetItemById($item.ID)
$deaditem.Delete()
}</div>
<div>
Advertisements

One thought on “Quick Powershell to delete all items in my Sharepoint list

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s