Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Fixed formatting in Title
Source Link
theChrisKent
  • 6.1k
  • 22
  • 34

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?

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 scripts 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 return : Content: My list is full of items with attachments, do you have an idea?

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 SharePoint 2013 it works but with SharePoint 2010, my script 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 returns : Content: My list is full of items with attachments, do you have any ideas?

Get attachments from sharepointSharePoint list with powershellPowerShell

Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 4 characters in body
Source Link
user3426869
  • 173
  • 2
  • 5
  • 15

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 scripts 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 return : Content: My list is full of items with attachments, do you have an idea?

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 scripts doesn't 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 return : Content: My list is full of items with attachments, do you have an idea?

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 scripts 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 return : Content: My list is full of items with attachments, do you have an idea?

edited
Source Link
Amal Hashim
  • 28.4k
  • 5
  • 32
  • 61
Loading
Source Link
user3426869
  • 173
  • 2
  • 5
  • 15
Loading