Search This Blog

Monday, December 8, 2014

Delete a List Item from a SiteCollection in SharePoint using Powershell

$site = Get-SPSite "http://contoso:1212/mysites/"
$web = $site.rootweb
$list = $web.Lists["Market"]
$caml=""
#optional filter
#<Where><Eq><FieldRef Name=""ContentType"" /><Value Type=""Text"">Form</Value></Eq></Where>"

$query=new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.Query=$caml

$items=$list.GetItems($query)
Write-Host $items.Count

$items | % { $list.GetItemById($_.Id).Delete() }

$web.Dispose()
$site.Dispose()

No comments:

Post a Comment