Introduction

In this blog, you will see how to get all the blobs from a specific container in Azure Storage Account using PowerShell.

Prerequisites

Install Azure PowerShell Module to run the script.

PowerShell Script

Open Notepad and paste the following script. Save the file as script.ps1.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $storageAccName="azstorageacc1122020"
  5. $containerName="container002"
  6. ## Connect to Azure Account
  7. Connect-AzAccount
  8. ## Function to get all the blobs
  9. Function GetAllBlobs
  10. {
  11. Write-Host -ForegroundColor Green "Retrieving all blobs from storage container.."
  12. ## Get the storage account
  13. $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
  14. ## Get the storage account context
  15. $ctx=$storageAcc.Context
  16. ## Get all the containers
  17. $containers=Get-AzStorageContainer -Context $ctx
  18. ## Get all the blobs
  19. $blobs=Get-AzStorageBlob -Container $containerName -Context $ctx
  20. ## Loop through all the blobs
  21. foreach($blob in $blobs)
  22. {
  23. write-host -Foregroundcolor Yellow $blob.Name
  24. }
  25. }
  26. GetAllBlobs
  27. ## Disconnect from Azure Account
  28. Disconnect-AzAccount

Open the Windows PowerShell window and navigate to the location where the script file was saved.

Run the following command.

.\script.ps1

Reference

https://docs.microsoft.com/en-us/powershell/module/az.storage/get-AzStorageblob?view=azps-3.3.0

Summary

In this blog, you saw how to get all the blobs from an Azure Storage Account using PowerShell.