Skip to content

Instantly share code, notes, and snippets.

@Dillie-O
Created October 20, 2016 22:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save Dillie-O/c68d8ea53eaf86f588d4716077448a64 to your computer and use it in GitHub Desktop.
Save Dillie-O/c68d8ea53eaf86f588d4716077448a64 to your computer and use it in GitHub Desktop.
PowerShell script to iterate all containers and blobs in a storage account and download it.
$destination_path = 'C:\Users\dilli\Downloads\media_dump'
$connection_string = '[AZURE_STORAGE_CONNECTION_STRING]'
$storage_account = New-AzureStorageContext -ConnectionString $connection_string
$containers = Get-AzureStorageContainer -Context $storage_account
Write-Host 'Starting Storage Dump...'
foreach ($container in $containers)
{
Write-Host -NoNewline 'Processing: ' . $container.Name . '...'
$container_path = $destination_path + '\' + $container.Name
if(!(Test-Path -Path $container_path ))
{
New-Item -ItemType directory -Path $container_path
}
$blobs = Get-AzureStorageBlob -Container $container.Name -Context $storage_account
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.'
@ankitrathod123
Copy link

@Dillie-O thanks for the script,
Actually I want all the network watcher logs in a centralize repository on a server,
to do that i have created a storage account where my logs are getting generated and now i want to download only the logs.json(block-blob) but not the containers and the sub-containers where the blobs are stored.

Can you please help me script for the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment