Intro

In the previous post I showed how to work with Azure Blob Service and CDN. In this post I am going to show how to work with Azure File Service from PowerShell. To get more information about Azure File Service features visit Introducing Microsoft Azure File Service.

Prerequisites

Refer to previous posts to get started with Azure Storage.

Code

Azure File storage is a service that offers file shares in the cloud using the standard Server Message Block (SMB) Protocol. Both SMB 2.1 and SMB 3.0 are supported. Applications running in Azure virtual machines or cloud services can mount a File storage share to access file data, just as a desktop application would mount a typical SMB share. Any number of Azure virtual machines or roles can mount and access the File storage share simultaneously.

Lets create a new file share:

PS C:\WINDOWS\system32> New-AzureStorageShare -Name "cloud-share"

   File End Point: https://default748347.file.core.windows.net/

Name                                                            LastModified
----                                                            ------------
cloud-share                                                     11/1/2016 2:35:34 AM +00:00

This code creates share with name cloud-share.

To get shares list run the following command:

PS C:\WINDOWS\system32> Get-AzureStorageShare

   File End Point: https://default748347.file.core.windows.net/

Name                                                            LastModified
----                                                            ------------
cloud-share                                                     11/1/2016 2:35:34 AM +00:00

This command gives the same output.

Now lets create a first directory inside our file share:

PS C:\WINDOWS\system32> New-AzureStorageDirectory -ShareName "cloud-share" -Path "dir1"

   Directory: https://default748347.file.core.windows.net/cloud-share

Type                Length Name
----                ------ ----
                         1 dir1

To add a file to the dir1 run the following command:

PS C:\WINDOWS\system32> Set-AzureStorageFileContent -ShareName cloud-share -Source C:\Projects\azure.jpg -Path dir1

To get files list in top level directory run the following command:

PS C:\WINDOWS\system32> Get-AzureStorageFile -ShareName cloud-share

   Directory: https://default748347.file.core.windows.net/cloud-share

Type                Length Name
----                ------ ----
                         1 dir1

To get files list in dir1 use the following snippet:

PS C:\WINDOWS\system32> Get-AzureStorageFile -ShareName cloud-share | ? { $_.Name -eq "dir1" } | Get-AzureStorageFile

   Directory: https://default748347.file.core.windows.net/cloud-share/dir1

Type                Length Name
----                ------ ----
                         1 azure.jpg

The best thing about Azure File Storage service is that it works in the same way as ordinary file share. You can mount it on both windows and linux VMs.

To mount our share on a windows vm run something like this:

PS C:\WINDOWS\system32> net use P: \\default748347.file.core.windows.net\cloud-share /u:default748347 YmSWd+PHrBH9CrMlEV9hcY2d9k4rhBReFjlKk171Aa8074liULNLdUL+RhFkaPQNNJ+l
kA1AGGjXfLfOMJgy1w==
The command completed successfully.

PS C:\WINDOWS\system32> P:
PS P:\> ls

    Directory: P:\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        11/1/2016   1:39 PM                dir1

In this way it is possible to work with Azure File Service share using good-old console commands.

To do the same thing on linux run following commands:

oleksii@ONLE63303XK7PX1:~$ sudo apt-get install cifs-utils
... lots of info ...
oleksii@ONLE63303XK7PX1:~$ mkdir cloud-share
oleksii@ONLE63303XK7PX1:~$ sudo mount -t cifs //default748347.file.core.windows.net/cloud-share ./cloud-share -o vers=3.0,username=default748347,password=YmSWd+PHrBH9CrMlEV9hcY2d9k4rhBReFjlKk171Aa8074liULNLdUL+RhFkaPQNNJ+lkA1AGGjXfLfOMJgy0w==,dir_mode=0777,file_mode=0777

This will mount the share to your Linux VM on Azure if your VM is in the same region with the storage account. Otherwise you will get:

mount error (13): Permission denied

You can find more info about different issue related to Azure File Service and Linux at How to use Azure File Storage with Linux

To delete a share run the following command:

PS C:\WINDOWS\system32> Remove-AzureStorageShare cloud-share

Summary

In this post I have showed how to perform basic operations on Azure File Service share using console. For more information visit Get started with Azure File storage on Windows. Even more information about Azure File Service architecture at Inside Azure File Storage. In the next post I will continue with Azure File Service, I am going to show how to work with Azure File Service from code.


;