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 came across while executing the Get-AzStorageBlob PowerShell command.
Table of Contents
Get-AzStorageBlob: Could not get the storage context
Recently, while working on one of the requirements where I was trying to execute the Get-AzStorageBlob PowerShell command. I was executing the below Azure PowerShell command.
Get-AzStorageBlob -Container "azure-webjobs-hosts" -IncludeVersion
The moment I ran this command, I got this error. The complete error message was as below.
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

Get-AzStorageBlob: Could not get the storage context [Solved]
So to fix this error, I had to pass in a storage context. So I ran the below PowerShell script.
$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 $myctx
After 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 following the below articles
Wrapping Up
In this Azure PowerShell article, we discussed 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 got while executing the Get-AzStorageBlob PowerShell command. Thanks for reading this article !!!

I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, 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.