Download Images from SharePoint Picture Library with PowerShell
Introduction
In this post we will see a generic function to download images to local folder from SharePoint Picture Library (Image Library) through PowerShell script
The script include
- Download images from SharePoint Picture Library. Folder structure is preserved as it is
Download Images
Following script will download images from Picture Library “MyTeamImagesLibrary” to local folder “C:\MySiteImages” of the server.
Users need to give values to three variables as below and execute the script file to download images
Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ######################## Variables ######################## $destination = "C:\MySiteImages" $webUrl = "http://sharepoint-devsite.com" $listUrl = "http://sharepoint-devsite.com/MyTeamImagesLibary" ############################################################## $web = Get-SPWeb -Identity $webUrl $list = $web.GetList($listUrl) function DownLoadImages($folderUrl) { $folder = $web.GetFolder($folderUrl) foreach ($file in $folder.Files) { #Ensure destination directory $destinationfolder = $destination + "/" + $folder.Url if (!(Test-Path -path $destinationfolder)) { $dest = New-Item $destinationfolder -type directory } #Downloading file $binary = $file.OpenBinary() $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create $writer = New-Object System.IO.BinaryWriter($stream) $writer.write($binary) $writer.Close() } } try { #Download root files DownLoadImages($list.RootFolder.Url) #Download files in folders foreach ($folder in $list.Folders) { DownLoadImages($folder.Url) } } catch { write-host $_.exception } finally { if($web -ne $null) { $web.Dispose() } }
Conclusion
Hope this generic function will be helpful. Happy Coding
August 4, 2013
В·
Adi В·
No Comments
Tags: download images, Powershell, SharePoint 2010, SharePoint 2013 В· Posted in: Powershell, Sharepoint 2010, SharePoint 2013
Leave a Reply