Created
October 20, 2016 22:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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