Azure, PowerShell

Deploying an Azure File Share with PowerShell

On Twitter, I saw a post by Scott Cate, a Developer Advocate for Microsoft, showing how to set up Azure File Shares with the GUI. Azure File Shares allow administrators to build SMB file shares on Azure. These can then be mounted by any supported OS such as Windows, Linux or MacOS. Being a PowerShell guy, I decided to dive into the code and see what I could come up with.

So my work-in-progress code is listed here and I’ll break it down for you. Basically, I have the code to build a new Azure Storage Account and create a File Share in an existing Azure Resource Group.

Note: All of my code was run via Azure Shell, a web-based secure shell for managing Azure. If you haven’t checked it out, you definitely should.

First, I needed to build the storage account that my share would be part of. For this, I used the new-AzureRMStorageAccount command to build that out. Also, I created variables to be used for all the inputs.

Once the storage account is created, the Azure Storage Account Key is stored in a variable for later use. Because there are two keys attached to each storage account (which you can re-key if needed) the first key, key1, is selected out.

With the key in hand, I create a variable for the storage context. The context encapsulates the storage account name and account key so I can work with my storage account.

Last, I’m going to create the share and verify the share was created.

As of this writing, the code is rudimentary so just copy it into Azure Shell to use. I plan to migrate the code to a parametized script that I’ll post on Github at a later date.

Was this helpful?

Let me know in the comments.


Leave a Reply

Your email address will not be published. Required fields are marked *

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see