1

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 : result sharepoint 2010

  • do you have the correct url on the SP 2010? One error Amal mentioned and then i am thinking about your URL, may be you dont have correct url – Waqas Sarwar MVP May 22 '15 at 12:20
0

It should be $w.Lists and not w.Lists

It seems you missed the $ sign.

  • Thanks but I have new error : PS C:\Users\devinfo\Desktop> echo $w Exception has been thrown by the target of an invocation. + CategoryInfo : NotSpecified: (:) [format-default], TargetInvocationException + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Microsoft.PowerShell.Commands.FormatDefaultCommand – user3426869 May 22 '15 at 10:28
  • On "echo $w", do you have an idea? – user3426869 May 22 '15 at 11:24
  • There is nothing when I try "$w.Title", it's a good news but the bad news is : why it didn't get my list in sharepoint 2010?? In another site in sharepoint 2013 my script get my library and attachments... – user3426869 May 22 '15 at 11:36

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.