Download all images from all picture libraries on Sharepoint Online

…this post was published on 2017 January 19.

You can use following script. Save it  on your PC or run it directly using .ISE.
All Images will be saved in specific picture library​.

You need to download locally 2 libraries , if on your machine you don’t have SP on-premises installed. These 2 libraries are
To run the script, you need to know the site’s URL and credentials to access the site.

This script Will permit to downlaod locally all pictures from al Picture libraries in Sharepoint Online site
You need to know 1 mandatory parameters:
    – URL         : the URL for the site
Based on thus URL, it will create in current directory a new directoryy, and there for each Picture library a sub-folder with pictures
This script can be use as it is or can be changed based on your needs. For more details please feel free and contact me
Romeo Donca, January 2017
[Parameter(Mandatory=$true,HelpMessage=”The url for the tenant where the picture library is, like”)][string]$Url
Add-Type -Path “local-path\Microsoft.SharePoint.Client.dll”
Add-Type -Path “local-path\Microsoft.SharePoint.Client.Runtime.dll”
Import-Module MSOnline
$global:cred = Get-Credential
Connect-MsolService -Credential $global:cred -ErrorAction SilentlyContinue
#$url = “”
if (!(Test-Path ($url.Replace(‘:’,”)).replace(‘/’,”)))
    New-Item -ItemType directory -name ($url.Replace(‘:’,”)).replace(‘/’,”)
    Set-Location  ($url.Replace(‘:’,”)).replace(‘/’,”)
    $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
    $clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
    $cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.username, $cred.Password) 
    $clientContext.Credentials = $cred
    $web = $clientContext.Web
    $lists = $web.Lists
foreach ($list  in $lists)
    if ($list.BaseTemplate -eq 109)
        “working on “+ $library
        $path0 = (($url.Replace(‘:’,”)).replace(‘/’,”))+’/’+$library
        if (!(Test-Path $library))
            new-item -ItemType Directory $library
        $mylist = $web.GetList($url+”/”+$library)
        $query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()
        $items = $mylist.GetItems($query)
        foreach ($item in $items)
            Invoke-WebRequest -Uri (‘’+$item.FieldValues[‘FileRef’]) -OutFile (Join-Path $library  $item.FieldValues[‘FileLeafRef’])
This entry was posted in Powershell, Sharepoint Online. Bookmark the permalink.