Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Does anybody know if there's some way to delete items from an SPList using PowerShell scripting?

If is this possible, has anybody any good tutorial?

Thanks!!!

share|improve this question
add comment

2 Answers

Here's the example.

Quote from link:

Delete Item -

The example below will count the items and loop down, read the name of the item, and if the item contains a 3, then it will delete that item.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = new-object Microsoft.SharePoint.SPSite("http://test.tomdaly.com") # is a legit url
$relweburl = "/Docs"
$web = $site.openweb($relweburl)
$list=$web.Lists["testList"] $listItems = $list.Items
$listItemsTotal = $listItems.Count

for ($x=$listItemsTotal-1;$x -ge 0; $x--)
{
    if($listItems[$x].name.Contains("3"))
    {
        Write-Host("DELETED: " + $listItems[$x].name)
        $listItems[$x].Delete()
    }
}
share|improve this answer
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. –  Stuart Pegg Aug 21 '12 at 14:06
add comment

Since you can access the object model it's pretty straight forward

asnp microsoft.sharepoint.powershell
$web = Get-SPWeb http://thesite/
$list = $web.Lists["NameOfList"]
$item = $list.GetItemById(1) 
$item.Delete()
share|improve this answer
    
ok. now, should I just save it as .ps and then run it from PS?? –  Bruno Ferreira Mar 6 '12 at 20:04
    
You just open a new powershell session and write the code...and yes, you could make it into a .ps1 script file if you need... –  Wictor Wilen MCA MCM MVP Mar 7 '12 at 14:32
    
OP should really start to accept answers - especially such obviously correct ones. –  curmudgeon Nov 22 '12 at 10:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.