1

I am trying to get attachment list with element ID from a sharepoint list. I found script to download attachment but I want to see how you would do it?

Thanks by advance,

++.

1

I resolved my problem :

$webUrl = "http://site.fr/"    
$library = "librarieName"
$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 = $webUrl + $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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.