Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 645
Peter PitLock Avatar asked Apr 26 '17 06:04

Peter PitLock


People also ask

How do I set storage context in PowerShell?

To create a new storage context, we need to use the New-AzStorageContext command but to use this command we need a storage account key or the connection string.

How do I create a container in storage account in PowerShell?

To create containers with PowerShell, call the New-AzStorageContainer cmdlet. There are no limits to the number of blobs or containers that can be created within a storage account. Containers cannot be nested within other containers.

Which of the below can be used to create a storage context?

The New-AzureStorageContext cmdlet creates an Azure Storage context.


1 Answers

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
like image 62
Gaurav Mantri Avatar answered Sep 18 '22 22:09

Gaurav Mantri