I am able to delete the attachments but not the folder associated to that attachment. Each item of the SharePoint list has an attachment attached to it. Each item's attachment is stored in that particular item's folder. The name of the folder is the ID of the folder. Can you please help me in deleting the folder attached to that item also.
This is code that I've written to delete the attachment. Help me with the code to delete the folder attached to the attachment.
if ($item["rjhg"] -eq "MT (A400M)")
{
$totalitemcount += $item["rjhg"].count;
for($i=$item.Attachments.count-1; $i -ge 0; $i--)
{
#Write-Host "Request ID :" $item["ID"]
[Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
Write-Host "Attatchment : "+$item.Attachments[$i]
$item.Attachments.Delete($item.Attachments[$i])
Write-Host "File Deleted: $item.Attachments[$i]"
$item.SystemUpdate()
#$allitems=$item.GetItems($query)
$filecount += $item.count
}
}