Could not get the 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 encountered while executing the Get-AzStorageBlob PowerShell command.

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" -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.

Could not get the storage context

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

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!