…covering cloud technologies such as Office 365, Azure, Amazon and, of course, SharePoint

Uploading a File to an Azure Storage Container

October 06, 2013 by Greg Carnie

Here’s the scenario: You have a file or blob of sorts that needs to be stored in an Azure Storage Container. That’s great - how do you get it to the container?? I have done this a few times and PowerShell is definitely my preferred method but I can never remember the steps. So, for my benefit and maybe others, here they are:

1: Get-AzurePublishSettingsFile

This will actually pop open IE (or your default browser), have you log into Azure, and then automatically download a .publishsettings file. You’ll need this file to import and set up your subscriptions. More information on this command can be found on MSDN here.

2: Import-AzurePublishSettingsFile

This import command does exactly as it describes, allows you to import the .publishsettings file from step 1 to your local PowerShell environment. When this import completes, it will tell you which subscription (only matters if you have multiple) has been set as the default subscription. If you need to change this, use step 3, if not, proceed to step 4. More information on this command can be found on MSDN here.

3: Select-AzureSubscription

This command is optional and simply sets the current Azure subscription to be used in the existing context. More information on this command can be found on MSDN here.

4: $context = New-AzureStorageContext -StorageAccountName -StorageAccountKey

This command generates a new Azure Storage Context and stores it in the variable $context. This will be used to tell PowerShell where the new blob is going to be stored in Azure. Your storage account name and key are both found within the Azure management site. More information on this command can be found on MSDN here.

5: Set-AzureStorageBlobContent -Blob ”” -Container -File ”” -Context $context -Force

This is where the magic happens. Set-AzureStorageBlobContent, again, does exactly as it describes. The Blob parameter is what the file (or blob) will be called once uploaded to the Azure container. Container is the target container within your Azure storage account. The File parameter is the full path and name of the source file that you want to uploaded to the Azure container. Context is the context variable from step 4. Once executed, you will see a status appear at the top of your PowerShell console which shows the percentage uploaded until the upload is complete. More information on this command can be found on MSDN here.

For bulk uploading, the best thought I have is to read a directory that is to be uploaded, then run this command in a loop. If anyone has a better way - please feel free to comment on this post and I’ll update it and give credit for the suggestion!

Written by Greg Carnie

I am a SharePoint consultant (Business Analyst by title) with Ideaca Knowledge Services based in Toronto, Canada. I have been actively working with SharePoint for three years now and have been specializing more in the developmental and architectural aspects of SharePoint. In a previous life I worked both with SAP and Microsoft Exchange. In my spare time (yes – I have figured out how to have a life outside of SharePoint – only took 3 years!!) I read, have started to get myself back into decent shape, and intend to spend a significant amount of time outside this summer.

You should follow Greg on Twitter