PowerShell – Download Azure Blob Container Content

You get all of your data into Azure or your application uploads/creates directly into Azure storage and then someone asks you to download the files….

This script below will help you download your files.

$StartTime = $(get-date)
$datetime = $(get-date -f yyyy-MM-dd_hh.mm.ss)

$connection_string = ''
$AzureBlobContainerName = ''

$destination_path = "t:\"
If(!(test-path $destination_path))
    New-Item -ItemType Directory -Force -Path $destination_path
$storage_account = New-AzureStorageContext -ConnectionString $connection_string

# Download from all containers
#$containers = Get-AzureStorageContainer -Context $storage_account

# Download from specific container
$containers = Get-AzureStorageContainer -Context $storage_account | Where-Object {$_.Name -eq "$AzureBlobContainerName"}

Write-Host 'Starting Storage Dump...'
foreach ($container in $containers)
    Write-Host -NoNewline 'Processing: ' . $container.Name . '...'
    $container_path = $destination_path + '\' + $container.Name
    $blobs = Get-AzureStorageBlob -Container $container.Name -Context $storage_account
    : hu b.nbn   Write-Host -NoNewline ' Downloading files...'    
    foreach ($blob in $blobs)
        $fileNameCheck = $container_path + '\' + $blob.Name       
        if(!(Test-Path $fileNameCheck ))
            Get-AzureStorageBlobContent `
            -Container $container.Name -Blob $blob.Name -Destination $container_path `
            -Context $storage_account
    Write-Host ' Done.'
Write-Host 'Download complete.'
$elapsedTime = $(get-date) - $StartTime
$totalTime = "{0:HH:mm:ss}" -f ([datetime]$elapsedTime.Ticks)
Write-Output " -OK $totalTime" | Out-String
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.