Skip to content

Instantly share code, notes, and snippets.

@0xhexmex
Forked from Dillie-O/get_all_media.ps1
Last active August 17, 2022 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xhexmex/bf19a37f7e3d4e497a04d680b3a60c16 to your computer and use it in GitHub Desktop.
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
# 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