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.
- ################# Azure Blob Storage - PowerShell ####################
-
- ## Input Parameters
- $resourceGroupName="azpractice"
- $storageAccName="azstorageacc1122020"
- $containerName="container002"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to get all the blobs
- Function GetAllBlobs
- {
- Write-Host -ForegroundColor Green "Retrieving all blobs from storage container.."
- ## Get the storage account
- $storageAcc=Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName
- ## Get the storage account context
- $ctx=$storageAcc.Context
- ## Get all the containers
- $containers=Get-AzStorageContainer -Context $ctx
- ## Get all the blobs
- $blobs=Get-AzStorageBlob -Container $containerName -Context $ctx
- ## Loop through all the blobs
- foreach($blob in $blobs)
- {
- write-host -Foregroundcolor Yellow $blob.Name
- }
- }
-
- GetAllBlobs
-
- ## Disconnect from Azure Account
- 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.