Part 2: Creating An Azure File Service File Share

To get started with Azure file service it is necessary to join the preview first. It is very easy to sign up and it did not take very long to receive confirmation that the file service feature was enabled on my account.

Create storage account

The next step is to create a new storage account, you need a new one because storage accounts created before Azure file service was activated will not be able to create file shares. The easiest way create a new storage account is using the Azure portal .

Create Storage Account

You can use the current portal or the preview portal to create a storage account but the preview portal does not support file service yet and it won’t show under your storage endpoints.

File service enabled

Create A Share

At the time of writing it was not possible to create a share from the portal but it can be done using Powershell or the REST API. I will cover using the API later on so for now I will use Powershell. You can download Azure Powershell using the Microsoft Web Platform Installer.

Install Azure PowerShell

PS: On my VM Azure Powershell did not work initially, it was missing some dlls and could not load the Azure Modules, in my case installing Azure SDK fixed the problem. Once installed you can launch it by typing “azure powershell” in the start menu.

Enter the following two commands to create a new share:
$ctx = New-AzureStorageContext storage_account_name storage_account_key
New-AzureStorageShare YourNewShareName -Context $ctx

In the code above storage_account_name is the name of the new storage account created earlier, just the name not the whole URL. Your storage_account_key can be retrieved from the portal by clicking Manage Access Keys under your storage account.Manage Storage Access Key

Once the share is created you have a few options to create directories and files in it.

  • Mounting the share in a VM

You can only mount the share on VMs that are in the same region as the file share. In a Powershell window or command prompt execute the following:

net use z: \\storage_account_name.file.core.windows.net\YourShareName /u:storage_account_name storage_account_key

Alternatively you can store your account key on the VM that will be mounting the share, this way you can mount shares without specifying your key every time. In a Powershell window or command prompt execute the following two commands:

cmdkey /add:storage_account_name.file.core.windows.net /user:storage_account_name /pass:storage_account_key

net use z: \\storage_account_name.file.core.windows.net\YourShareName

Now you can use this share like you would any other windows file share and perform the usual file operations on it

  • Using Azure Powershell

#Create a context
$ctx = New-AzureStorageContext storage_account_name storage_account_key


#Retrieve the share
$share = Get-AzureStorageShare -Context $ctx -Name YourShareName

#Create a new directory in the share
New-AzureStorageDirectory -Share $share -Path DirectoryName

# Upload a local file to the directory you just created
Set-AzureStorageFileContent -Share $share -Source C:\Temp\File.txt -Path DirectoryName

# List the contents of the directory you created
Get-AzureStorageFile -Share YourShareName -Path NewFolder

There are many more cmdlets for Azure Storage, I suggest having a look at the documentation to see what is available.

In my next post will explore the file service API.

Francois Delport

Published by

Francois Delport

I am a cloud and devops consultant, technology fan and previously a professional C# developer with a keen interest in system design and architecture. Currently I am involved in projects using Azure, the Microsoft stack and DevOps. I am based in Melbourne, Australia. Email: [email protected]

Leave a Reply

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