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!!!
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()
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()
}
}