Thursday, April 28, 2011

Delete All Itmes in List using PowerShell

Delete All Itmes in List using PowerShell

$SITEURL = "http://spsrv:8888"

$site = new-object Microsoft.SharePoint.SPSite ( $SITEURL )
$web = $site.OpenWeb()
"Web is : " + $web.Title

# Enter name of the List below
$oList = $web.Lists["Contract Expiry Alert"];

"List is :" + $oList.Title + " with item count " + $oList.ItemCount

$collListItems = $oList.Items;
$count = $collListItems.Count - 1

for($intIndex = $count; $intIndex -gt -1; $intIndex--)
{
"Deleting : " + $intIndex
$collListItems.Delete($intIndex);
}