question

ELALAOUILahcenADM-7076 avatar image
0 Votes"
ELALAOUILahcenADM-7076 asked SumanthMarigowda-MSFT commented

Quering Azure Storage Account using Powershell

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://docs.microsoft.com/en-us/azure/storage/scripts/storage-blobs-container-calculate-size-powershell

Thank you for your help and best regards

windows-server-powershellazure-storage-accountsazure-blob-storage
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

SumanthMarigowda-MSFT avatar image
0 Votes"
SumanthMarigowda-MSFT answered

@ELALAOUILahcenADM-7076 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.



image.png (91.5 KiB)
image.png (1.1 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ELALAOUILahcenADM-7076 avatar image
0 Votes"
ELALAOUILahcenADM-7076 answered SumanthMarigowda-MSFT commented

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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@ELALAOUILahcenADM-7076 Firstly, apologies for the delay in responding here!

Export process properties to a CSV file

Example $output | Export-Csv -path c:\scripts\test.csv -NoTypeInformation

Just like we added name, add the other fields which ever is required. You can customize the script has per your requirements


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



0 Votes 0 ·
image.png (1.1 KiB)