Home > Work > Quick Powershell to delete all items in my Sharepoint list

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.
<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>

via François on Sharepoint http://sharepointfrancois.wordpress.com/2012/10/31/quick-powershell-to-delete-all-items-in-my-sharepoint-list/

François Souyri
French native Sharepoint Consultant living in London. A crossway between a designer, developer and system architect. Prefers stretching the limit of out-of-the-box features rather than breaking them into code. When not working with Microsoft Sharepoint François is often found on Web2.0 News sites and related social networking tools.

This article has been cross posted from sharepointfrancois.wordpress.com/ (original article)

Advertisement
Categories: Work Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: