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

Peter PitLock picture Peter PitLock · Apr 26, 2017 · Viewed 15.1k times · Source

I am using powershell with Azure cmdlets to try and simply see items in blob storage

  $StorageContext = New-AzureStorageContext -StorageAccountName 'myblobname' -StorageAccountKey '2341231234asdff2352354345=='
  $Container = Get-AzureStorageContainer -Name 'mycontainer' -Context $StorageContext  
  $blobs = Get-AzureStorageBlob -Container  $Container

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

I am 100% sure that the credentials are correct (just random shortened credential data in this post)

Why would I get this error?

Is AzureRM used? The AzureRM version is listed as 3.8.0. Which versions of which scripts would I need for this to work?

Answer

Stopped Contributing picture Stopped Contributing · Apr 26, 2017

You would need to include StorageContext here as well:

$blobs = Get-AzureStorageBlob -Container  $Container

So your code would be:

$blobs = Get-AzureStorageBlob -Container $Container -Context $StorageContext