Here is a powershell script to save SharePoint list attachments to a folder
Reference : http://bhatiaashish.blogspot.com.au/2012/08/powershell-script-to-download.html
Add-PsSnapin Microsoft.SharePoint.PowerShell
function downloadListAttachments ( ){
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$siteURL,
[Parameter(Mandatory=$True)]
[string]$listName,
[string]$Path
)
$tempLocation = $Path
$w = Get-SPWeb $siteURL
$l = $w.Lists[$listName]
foreach ($listItem in $l.Items)
{
Write-Host " Content: " $listItem.ID
$destinationfolder = $tempLocation
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
foreach ($attachment in $listItem.Attachments)
{
$attachment
$file = $w.GetFile($listItem.Attachments.UrlPrefix + $attachment)
$bytes = $file.OpenBinary()
$path = $destinationfolder + "\" + $attachment
Write "Saving $path"
$fs = New-Object System.IO.FileStream($path, "OpenOrCreate")
$fs.Write($bytes, 0 , $bytes.Length)
$fs.Close()
}
}
}
downloadListAttachments -siteURL "https://abc" -listName "ListName" -Path "C:\Temp"
Reference : http://bhatiaashish.blogspot.com.au/2012/08/powershell-script-to-download.html
Comments