I made this script :
$webUrl = "http://site.fr/"
$library = "Qualified Information"
$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
if($linkAttachment){
$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
With a SharePoint 2013 it works but with SharePoint 2010, my scriptsscript doesn't get the list :
Exception calling "GetFile" with "1" argument(s): "Value does not fall within the expected range."
If I debug $l
, it's null
My Write-Host
Content: $listItem.ID
just returnreturns : Content:
My list is full of items with attachments, do you have an ideaany ideas?