How to read contents of a CSV in Azure Blob storage using powershell

Biju Mathew 481 Reputation points
2023-01-27T07:36:01.7+00:00

Hi, Is there any way to read the contents of a file in Azure blob using Powershell?

I tried Get-AzStorageBlobContent but this stores the file in a local folder.

I don't want to store the file locally.

My requirment is to read the file from blob and then i will pipe the contents onto another step.

Is this possible please?

Thanks

Windows for business | Windows Server | User experience | PowerShell
{count} votes

Accepted answer
  1. Peter T 331 Reputation points
    2023-01-27T11:40:44.3666667+00:00

    Hi,

    You can download the file contents into memory via DownloadText() method:

    #Get Storage Account context
    $context = New-AzStorageContext -StorageAccountName "<storage-account>" -SasToken "<sas-token>" # or -StorageAccountKey, you can use your preferred method for authentication
    #Get reference for container
    $container = Get-AzStorageContainer -Name "<container-name>" -Context $context
    #Get reference for file
    $client = $container.CloudBlobContainer.GetBlockBlobReference("<file-name>")
    #Read file contents into memory
    $file = $client.DownloadText()
    

    This is possible because Get-AzStorageContainer returns an "AzureStorageContainer" object.

    Azure SDK reference for the method.

    BR,

    Peter

    1 person found this answer helpful.

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.