9
votes

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.

3

3 Answers

20
votes

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
3
votes

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.

2
votes

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.