Skip to content

Quick Powershell to delete all items in my Sharepoint list

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.
[sourcecode language=”powershell”]<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>[/sourcecode]