In this Azure PowerShell article, we will discuss how to fix the error “Could not get the storage context. Please pass in a storage context or set the current storage context,” which I encountered while executing the Get-AzStorageBlob PowerShell command.
Table of Contents
Could not get the storage context
Recently, while working on one of the requirements, I tried to execute the Get-AzStorageBlob PowerShell command. I executed the below Azure PowerShell command.
Get-AzStorageBlob -Container "azure-webjobs-hosts" -IncludeVersionThe moment I ran this command, I got this error. The complete error message is as follows.
Get-AzStorageBlob : Could not get the storage context. Please pass in a storage
context or set the current storage context.
At line:2 char:1
Get-AzStorageBlob -Container "azure-webjobs-hosts" -IncludeVersion
~~~~~~~~~~~~~~
CategoryInfo : CloseError: (:) [Get-AzStorageBlob], InvalidOperationEx
ception
FullyQualifiedErrorId : InvalidOperationException,Microsoft.WindowsAzure.Comman
ds.Storage.Blob.Cmdlet.GetAzureStorageBlobCommand
You can see the same output below.

Solution
To fix this error, I had to pass in a storage context, so I ran the PowerShell script below.
$sARG = "DEMORG2"
$sAName = "demorg2913f"
$sAKey = (Get-AzStorageAccountKey -ResourceGroupName $sARG -AccountName $sAName).Value[0]
$myctx = New-AzStorageContext -StorageAccountName $sAName -StorageAccountKey $sAKey
Get-AzStorageBlob -Container "azure-webjobs-hosts" -Context $myctxAfter executing the above PowerShell script, I got the below-expected output.
AccountName: demorg2913f, ContainerName: azure-webjobs-hosts
Name BlobType Length ContentType LastModi
fied
---- -------- ------ ----------- --------
locks/demotstest/... BlockBlob 0 application/octet-stream 2023-...
You can see the same output below

You may also like the following articles below
Wrapping Up
In this Azure PowerShell article, we discussed how to fix the error “Could not get the storage context,” which I got while executing the Get-AzStorageBlob PowerShell command. Thanks for reading this article !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
