I made this script to get all attachments from a list, it works on Sharepoint 2013 serveur but on Sharepoint 2010 I don't have any result... :
$webUrl = "https://site.fr"
$library = "Contacts"
$spSite = new-object Microsoft.SharePoint.SPSite($webUrl)
$w = $spSite.OpenWeb()
$l = $w.Lists[$library]
$resultHashtable = @{}
foreach ($listItem in $l.Items)
{
Write-Host " Content: " $listItem.ID
foreach ($attachment in $listItem.Attachments)
{
$file = $w.GetFile($listItem.Attachments.UrlPrefix + $attachment)
$linkAttachment = "http://site.fr" + $file.ServerRelativeUrl
Write-Host "http://site.fr"$file.ServerRelativeUrl
$resultHashtable.Add($listItem.ID, $linkAttachment)
}
}
#Export CSV
$resultHashtable.GetEnumerator() | Sort-Object -Property Name -Descending |
Select-Object -Property @{n='SiteURL';e={$_.Name}},Value |
Export-Csv -Path Attachments.csv -NoTypeInformation
Result on 2013 :
PS E:\Scripts> $spSite = new-object Microsoft.SharePoint.SPSite($webUrl)
PS E:\Scripts> $w = $spSite.OpenWeb()
PS E:\Scripts> $l = $w.Lists[$library]
PS E:\Scripts> echo $l
Lists : {Annonces, Calendrier,
73ea2520-321e-4623-b14e-9ea313889487, Contacts...}
ParentWeb : Citadisation Ligne A (3170)
Result on 2010 :