-
-
Save 0xhexmex/bf19a37f7e3d4e497a04d680b3a60c16 to your computer and use it in GitHub Desktop.
PowerShell script to iterate all containers and blobs in a storage account and download it. - forked to use Az module instead of Azure, and storage account name instead of connection string
This file contains 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
# Usage: Install-Module Az > Import-Module Az > Connect-AzAccount > Get-AzStorageAccount > replace the $storage_account variable in the script > run the script | |
$destination_path = '.' | |
# $connection_string = '[AZURE_STORAGE_CONNECTION_STRING]' | |
$storage_account = '' | |
$storage_account = New-AzStorageContext -StorageAccountName $storage_account | |
$containers = Get-AzStorageContainer -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-AzStorageBlob -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-AzStorageBlobContent ` | |
-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