My observations so far with the Azure PowerShell experience have been somewhat mixed and the example in this post will give you a flavour of that. I wanted to create a new Storage Blob Container via PowerShell, rather than through the below process in the web portal:

I looked for cmdlets which could potentially be used:

View the code on Gist.

However, it returned nothing from the AzureRM module, only the Azure module. (There are currently two modules you need to use when working with Azure, some more info here and here) To say this can get confusing when you are new to the topic is an understatement, hopefully this situation is going to improve significantly ASAP.

So it looks like I need to use New-AzureStorageContainer from the original Azure module, however there do not appear to be any examples which show you how to add it into the desired place, i.e. Resource Group and Storage Account:

So far I have found two different ways to get this done:

1)Set the current Storage Account



I found a StackOverflow post with an example. You need to first of all call a cmdlet from the AzureRM module to set the current Storage Account (note line 2 is the weird response you get from running the command in line 1, i.e. just a string with the name of the current Storage Account, not an object representing it):

View the code on Gist.

Now I can use New-AzureStorageContainer and it will get created in the correct place:

View the code on Gist.

2) Use Storage Account Keys

Within a Storage Account are two Access keys which can be used for automation:

We only need one of the keys, but the following will retrieve both and then we pick out the first key value:

View the code on Gist.

Now using one of the key values we can set the Storage Context:

View the code on Gist.

Note: the above doesn’t actually seem to perform any validation on whether a Storage Account with that name exists. I initially had a typo in the name and when using the next command generated the error: New-AzureStorageContainer : The remote name could not be resolved: ‘jmtest01.blob.core.windows.net’

Now if we have used the correct name for an existing Storage Account we can create the Storage Container using the generated Storage Context:

View the code on Gist.

Please leave a comment if I have missed an easier way to do it, I’d love to know 🙂