Saturday, April 26, 2014

Can not find your azure storage credentials – Windows Azure Storage


I was performing an operation in powershell to copy blob from one storage account to another storage account. But before that I was trying to get the blobs present in container by using powershell command –
Get-AzureStorageBlob -Container vhds
When you fire this command you will receive error stated as below –
“Can not find your azure storage credentials.”
The reason is you have not set the context for current storage operation. The total scripts should be as follows –

First if you have set up the azure account then does it by command –
Add-AzureAccount
This will open a pop up to enter credentials for Microsoft account. Then select the subscription under which your storage account resides. To select the subscription use following commands –
Select-AzureSubscription -SubscriptionName "Your Subscription Name"
Then get storage account information and primary for storage account


$sourceStorageAccount = Get-AzureStorageAccount -StorageAccountName “Storageaccountname”
$sourceStorageKey = (Get-AzureStorageKey -StorageAccountName “Storageaccountname”).Primary
Then we need to set the context for current storage account.
$sourceContext = New-AzureStorageContext -StorageAccountName “Storageaccountname”
-StorageAccountKey $sourceStorageKey

This set’s everything required and now you can fire command on Azure storage like below –
Get-AzureStorageBlob -Container vhds -Context $destContext

This lists all the blobs as shown below –

In the same way if you receive error while performing operation on Azure storage using powershell make sure that you follow all the steps above mentioned from adding azure account to setting the storage context.
Hope this helps.
Cheers…

No comments:

Post a Comment