Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-AzureStorageBlob throws Can not find your azure storage credential

I have just started using Azure and I am facing issues using the PowerShell cmdlets to work with my storage account.

I have created a Storage account and a container in that storage account. Next I installed the Azure Powershell SDK and command lets etc. and imported the publishsettings file. When I do the Get-AzureSubscription or Get-AzureStorageAccount command it correctly shows my subscription in the PowerShell console along with various storage end points.

However if I do a Get-AzureStorageBlob call or a Set-AzureStorageBlobContent I get the following error

Get-AzureStorageBlob : Can not find your azure storage credential. Please set current storage account using
"Set-AzureSubscription" or set the "AZURE_STORAGE_CONNECTION_STRING" environment variable.

I am literally at wits ends here. A Google search on this error string only brings up references to code on Github etc. Would really appreciate some help.

like image 393
Nikhil Avatar asked Sep 13 '13 21:09

Nikhil


People also ask

How do I get Azure Storage account key in PowerShell?

In this blog, you will see how to retrieve and refresh Azure Storage Account Access Keys using PowerShell. Install Azure PowerShell Module to run the script. Open Notepad and paste the below code. Save the file as script.


3 Answers

Right so I finally managed to do this! Here is the overall details on how to use PowerShell to create a blob in Azure and store a file there.

http://www.nikgupta.net/2013/09/azure-blob-storage-powershell/

$context = New-AzureStorageContext -StorageAccountName FunkyStorage -StorageAccountKey {Enter your storage account key here}

Set-AzureStorageBlobContent -Blob "MyFunkyBlob" -Container FunkyContainer-File "c:\temp\1.txt" -Context $context -Force
like image 123
Nikhil Avatar answered Oct 01 '22 06:10

Nikhil


You may need to set the 'current' subscription to use. For that, you must run Select-AzureSubscription.

If you run Get-AzureSubscription, you'll see all subscriptions in your publish settings. One of those subscriptions should be set as the default. As you scroll through the result list, you'll see one property, IsDefault for each subscription, set to True or False. If the subscription you're using is set to False, run:

Select-AzureSubscription -SubscriptionName mysub

Hopefully that fixes the issue you're running into.

like image 20
David Makogon Avatar answered Oct 01 '22 05:10

David Makogon


Just a quick FYI: you can do this another (and faster way). I build a web language atop Windows PowerShell that heavily integrates with Azure. It's called PowerShell Pipeworks.

You can use 4 cmdlets to interact with the blobs:

  • Get-Blob
  • Import-Blob
  • Export-Blob
  • Remove-Blob

All take a -StorageAccount and a -StorageKey, and also a -StorageAccountSetting and a -StorageKeySetting. You can save creds to disk (or for use in a web app by using Add-SecureSetting). Once any blob cmdlet has a storage account, it will continue to reuse it.

Export-Blob is also handy in that you can pipe in a directory to it, and it will create the right content types, and provide -Public, which will mark the container it's stored in as public.

These cmdlets are a notch older (~3 months) than the Azure ones, and still about 3/4ths the time to execute (I believe a major chunk of this is their slower lookup on credentials), and are worth a try.

like image 44
Start-Automating Avatar answered Oct 01 '22 05:10

Start-Automating