Quering Azure Storage Account using Powershell

EL ALAOUI Lahcen (ADM) 1 Reputation point
2021-10-07T13:48:04.453+00:00

Hello,

I'm trying to put in place a powershell script to export all available files in my storage account with the maximum of details, my goal is to have something like this :

Blob name | Folder name | File name | Type | Created datetime | Last modification datetime | Size | Lease State | and the full path (Parent folder/s)

I have already found some scripts in some forums but it does not fit this need, like :

https://stackoverflow.com/questions/36162435/how-to-get-size-of-azure-container-in-powershell
https://learn.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powershell

Thank you for your help and best regards

Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,679 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,425 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Sumarigo-MSFT 43,411 Reputation points Microsoft Employee
    2021-10-08T16:55:24.353+00:00

    @EL ALAOUI Lahcen (ADM) Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

        $blobs = Get-AzStorageBlob -Container $ContainerName -Context $ctx   
          
        foreach ($blob in $blobs)  
        {  
                 
        Write-Host $blob.Name, $blob.ICloudBlob.Properties.LeaseState  
        }  
          
        foreach ($blob in $blobs)  
        {  
           Write-Host ($blob.Name + "|" + $blob.ICloudBlob.Properties.LeaseState + "|" + $blob.LastModified + "|" + $blob.BlobType)  
        }  
          
        foreach ($blob in $blobs)  
        {  
        Write-Host ($blob.name + "|" +$blob.size + "|" + $blob.accesstier)  
        }  
    

    Note: There is no concept of Folder in Storage unless its ADLS Gen 2. File name and Blob Name is same

    138889-image.png

    Please let us know if you have any further queries. I’m happy to assist you further.

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

    Please do not forget to 138896-image.png and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

  2. EL ALAOUI Lahcen (ADM) 1 Reputation point
    2021-10-08T18:42:13.937+00:00

    Thank you very much this is very helpful :)

    I have to more queries :
    1- it seems that the query doesn't fetch the size ?
    2- How can I put the data in a csv output ?

    It's my first post and I'm glad to be here :) Thanks again for your help