Tags

,

The followong script is to recursively remove documents from a library only. A few examples for Announcement from here.

To remove the items just uncomment the $items | % { $_.Delete() }

    #Start-Transcript ‘c:\powershell\logs\transcript.txt’
    [System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
	$weburl = "http://winsvr2008/kenny"
	$contenttype = "Document"
    $site = new-object Microsoft.SharePoint.SPSite($weburl)
    $web = $site.OpenWeb()
    $list = $web.Lists["Test Doc"]
	
	# $list | foreach { $_.Items | select Name, ContentType }

    $caml='<Where><Eq><FieldRef Name="ContentType" /><Value Type="Text">'+ $contenttype + '</Value></Eq></Where>'

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

    $items=$list.GetItems($query)

    # Pipe results to a loop and delete each element

    #$items | % { $_.Delete() }
	$items.Count
	$items |  select Name 

    $web.Dispose()
    $site.Dispose()
    #Stop-Transcript