Script to download files from Azure Storage account which specified in csv file

Abduazim Sobitov 101 Reputation points
2022-08-04T02:46:54.973+00:00

Hi team,

Newbie in scripting here. We have a storage account where we store nearly thousand files. Each week I have a list of files which I need to download in order to complete some manual workaround from this storage account.

The list of files is getting bigger, nearly 300 files now. Is there a way to write a script using Azure CLI to download specific list of files.

Thank for help

Azure Storage
Azure Storage
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
3,535 questions
0 comments No comments
{count} votes

Accepted answer
  1. Dillon Silzer 57,831 Reputation points Volunteer Moderator
    2022-08-04T05:03:05.607+00:00

    Hi @Abduazim Sobitov

    You can use the script suggested on Stack Overflow (answer by John Bull):

    Download a list of specific files from Azure Blob

    https://stackoverflow.com/questions/69408837/download-a-list-of-specific-files-from-azure-blob

    $accountName = "account-name"  
    $accountKey = "account-key"  
    $containerName = "container-name"  
    $context = New-AzStorageContext -StorageAccountName $accountName -StorageAccountKey $accountKey  
    $destination = "C:\temp"  
      
    $blobNames = Get-Content $destination\list.txt  
      
    For ($i=0; $i -lt $blobNames.Length; $i++) {  
        $blob = $blobNames[$i]  
        Write-Host "Downloading $blob. Please wait."  
        Get-AzStorageBlobContent -Blob $blob -Container $containerName -Destination $destination -Context $context -Verbose  
    }  
    

    It'll work like a charm, given that the text file that holds a list of file names for the blobs you need to download is located in the '$destination' directory (could be any directory on your PC, though). p.s., the files just need to be listed as one column (separated by a caret return, i.e., "\n" at the end of each file name). Thanks @Anonymous Mantri for the solution.

    Documentation for Get-AzStorageBlobContent

    https://learn.microsoft.com/en-us/powershell/module/az.storage/get-azstorageblobcontent?view=azps-8.2.0

    You will also need to ensure you have the Az Module (Install the Azure Az PowerShell module)

    https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-8.2.0

    -------------------------------

    If this is helpful please mark as correct answer.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.