Get-AzStorageBlob: Could not get the storage context. Please pass in a storage context or set the current storage context.

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.

Get-AzStorageBlob: Could not get the storage context. Please pass in a storage context or set the current storage context.

Recently, while working on one of the requirements, 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 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

Get-AzStorageBlob: Could not get the storage context

Get-AzStorageBlob: Could not get the storage context. Please pass in a storage context or set the current 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

Could not get the storage context

You may also like following the articles below

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 !!!