Delete the attachments for the specified SharePoint 2010 list item using web service in powershell

Steps Involved:

  1. Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
  2. Run the following script.

Powershell Script:

 
## Input Parameters required for Deleting the attachments for the specified SharePoint list item
$uri="http://serverName:10736/sites/ECT/_vti_bin/Lists.asmx?wsdl"
[
string] $listItemId="2"
[
string] $listName="List"


$listWebServiceReference = New-WebServiceProxy -Uri $uri -UseDefaultCredential
[
System.Xml.XmlNode]$xmlNode=$listWebServiceReference.GetAttachmentCollection($listName,$listItemId)
write-host -ForegroundColor Magenta "Deleting all the attachment for the specified SharePoint list item........."
foreach($node in $xmlNode.Attachment)
{
write-host -ForegroundColor Green "Deleting the attachment " $node
$listWebServiceReference.DeleteAttachment($listName,$listItemId,$node)
}




Ebook Download
View all
Learn
View all