Azure Files is Microsoft's easy-to-use cloud file system. Azure file shares can be mounted in Windows, Linux, and macOS. This guide shows you how to create an SMB Azure file share using either the Azure portal, Azure CLI, or Azure PowerShell module.
If you don't have an Azure subscription, create a free account before you begin.
If you don't have an Azure subscription, create a free account before you begin.
Use Azure Cloud Shell
Azure hosts Azure Cloud Shell, an interactive shell environment that you can use through your browser. You can use either Bash or PowerShell with Cloud Shell to work with Azure services. You can use the Cloud Shell preinstalled commands to run the code in this article, without having to install anything on your local environment.
To start Azure Cloud Shell:
Option
Example/Link
Select Try It in the upper-right corner of a code block. Selecting Try It doesn't automatically copy the code to Cloud Shell.
Go to https://shell.azure.com, or select the Launch Cloud Shell button to open Cloud Shell in your browser.
Select the Cloud Shell button on the menu bar at the upper right in the Azure portal.
To run the code in this article in Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block to copy the code.
Paste the code into the Cloud Shell session by selecting Ctrl+Shift+V on Windows and Linux, or by selecting Cmd+Shift+V on macOS.
Select Enter to run the code.
If you'd like to install and use PowerShell locally, this guide requires the Azure PowerShell module Az version 7.0.0 or later. To find out which version of the Azure PowerShell module you're running, execute Get-InstalledModule Az. If you need to upgrade, see Install Azure PowerShell module. If you're running PowerShell locally, you also need to run Login-AzAccount to log in to your Azure account. To use multi-factor authentication, you'll need to supply your Azure tenant ID, such as Login-AzAccount -TenantId <TenantId>.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you are running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For additional sign-in options, see Sign in with the Azure CLI.
When you're prompted, install Azure CLI extensions on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
This article requires version 2.0.4 or later of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
By default, Azure CLI commands return JavaScript Object Notation (JSON). JSON is the standard way to send and receive messages from REST APIs. To facilitate working with JSON responses, some of the examples in this article use the query parameter on Azure CLI commands. This parameter uses the JMESPath query language to parse JSON. To learn more about how to use the results of Azure CLI commands by following the JMESPath query language, see the JMESPath tutorial.
A storage account is a shared pool of storage in which you can deploy an Azure file share or other storage resources, such as blobs or queues. A storage account can contain an unlimited number of shares. A share can store an unlimited number of files, up to the capacity limits of the storage account.
To create a storage account using the Azure portal:
Under Azure services, select + to create a resource.
Select Storage account to create a storage account.
Under Project details, select the Azure subscription in which to create the storage account. If you have only one subscription, it should be the default.
Select Create new to create a new resource group. For the name, enter myResourceGroup.
Under Instance details, provide a name for the storage account such as mystorageacct followed by a few random numbers to make it a globally unique name. A storage account name must be all lowercase and numbers, and must be between 3 and 24 characters. Make a note of your storage account name. You will use it later.
In Region, select East US.
In Performance, keep the default value of Standard.
In Redundancy, select Locally redundant storage (LRS).
Select Review + Create to review your settings and create the storage account.
When you see the Validation passed notification, select Create. You should see a notification that deployment is in progress.
PowerShell - Create a resource group
A resource group is a logical container into which Azure resources are deployed and managed. If you don't already have an Azure resource group, create a new one with the New-AzResourceGroup cmdlet. You need a resource group to create a storage account.
The following example creates a resource group named myResourceGroup in the West US 2 region:
A storage account is a shared pool of storage you can use to deploy Azure file shares.
This example creates a storage account using the New-AzStorageAccount cmdlet. The storage account is named mystorageaccount<random number> and a reference to that storage account is stored in the variable $storageAcct. Storage account names must be unique, so use Get-Random to append a random number to the name to make it unique.
A resource group is a logical container in which Azure resources are deployed and managed. If you don't already have an Azure resource group, you can use the az group create command to create one. You need a resource group to create a storage account.
The following example creates a resource group named myResourceGroup in the West US 2 location:
export resourceGroupName="myResourceGroup"
region="westus2"
az group create \
--name $resourceGroupName \
--location $region \
--output none
CLI - Create a storage account
A storage account is a shared pool of storage in which you can deploy Azure file shares.
The following example creates a storage account using the az storage account create command. Storage account names must be unique, so use $RANDOM to append a random number to the name to make it unique.
Now that you've created a storage account, you can create your first Azure file share by using the New-AzRmStorageShare cmdlet. This example creates a share named myshare with a quota of 1024 GiB. The quota can be a maximum of 5 TiB, or 100 TiB with large file shares enabled on the storage account.
Now that you've created a storage account, you can create your first Azure file share by using the az storage share-rm create command. This example creates a share named myshare with a quota of 1024 GiB. The quota can be a maximum of 5 TiB, or 100 TiB with large file shares enabled on the storage account.
To demonstrate uploading a file, you first need to create or select a file to be uploaded. You may do this by whatever means you see fit. Once you've decided on the file you would like to upload:
Select the myDirectory directory. The myDirectory panel opens.
In the menu at the top, select Upload. The Upload files panel opens.
Select the folder icon to open a window to browse your local files.
Select a file and then select Open.
In the Upload files page, verify the file name and then select Upload.
When finished, the file should appear in the list on the myDirectory page.
To demonstrate how to upload a file using the Set-AzStorageFileContent cmdlet, we first need to create a file inside your PowerShell Cloud Shell's scratch drive to upload.
This example puts the current date and time into a new file on your scratch drive, then uploads the file to the file share.
# this expression will put the current date and time into a new file on your scratch drive
cd "~/CloudDrive/"
Get-Date | Out-File -FilePath "SampleUpload.txt" -Force
# this expression will upload that newly created file to your Azure file share
Set-AzStorageFileContent `
-Context $storageAcct.Context `
-ShareName $shareName `
-Source "SampleUpload.txt" `
-Path "myDirectory\SampleUpload.txt"
If you're running PowerShell locally, substitute ~/CloudDrive/ with a path that exists on your machine.
After uploading the file, you can use Get-AzStorageFile cmdlet to check to make sure that the file was uploaded to your Azure file share.
To demonstrate how to upload a file by using the az storage file upload command, first create a file to upload on the Cloud Shell scratch drive. In the following example, you create and then upload the file:
cd ~/clouddrive/
date > SampleUpload.txt
az storage file upload \
--account-name $storageAccountName \
--account-key $storageAccountKey \
--share-name $shareName \
--source "SampleUpload.txt" \
--path "myDirectory/SampleUpload.txt"
If you're running Azure CLI locally, substitute ~/clouddrive with a path that exists on your machine.
After you upload the file, you can use the az storage file list command to make sure that the file was uploaded to your Azure file share:
az storage file list \
--account-name $storageAccountName \
--account-key $storageAccountKey \
--share-name $shareName \
--path "myDirectory" \
--output table
You can download a copy of the file you uploaded by right-clicking on the file and selecting Download. The exact experience will depend on the operating system and browser you're using.
You can use the Get-AzStorageFileContent cmdlet to download a copy of the file you uploaded to the scratch drive of your Cloud Shell.
# Delete an existing file by the same name as SampleDownload.txt, if it exists because you've run this example before.
Remove-Item `
-Path "SampleDownload.txt" `
-Force `
-ErrorAction SilentlyContinue
Get-AzStorageFileContent `
-Context $storageAcct.Context `
-ShareName $shareName `
-Path "myDirectory\SampleUpload.txt" `
-Destination "SampleDownload.txt"
After downloading the file, you can use the Get-ChildItem to see that the file has been downloaded to your PowerShell Cloud Shell's scratch drive.
You can use the az storage file download command to download a copy of the file that you uploaded to the Cloud Shell scratch drive:
# Delete an existing file by the same name as SampleDownload.txt, if it exists, because you've run this example before
rm -f SampleDownload.txt
az storage file download \
--account-name $storageAccountName \
--account-key $storageAccountKey \
--share-name $shareName \
--path "myDirectory/SampleUpload.txt" \
--dest "SampleDownload.txt" \
--output none
When you're done, delete the resource group. Deleting the resource group deletes the storage account, the Azure file share, and any other resources that you deployed inside the resource group.
Select Home and then Resource groups.
Select the resource group you want to delete.
Select Delete resource group. A window opens and displays a warning about the resources that will be deleted with the resource group.
Enter the name of the resource group, and then select Delete.
When you are done, you can use the Remove-AzResourceGroup cmdlet to delete the resource group and all resources contained in the resource group.
Remove-AzResourceGroup -Name myResourceGroup
When you are done, you can use the az group delete command to delete the resource group and all resources contained in the resource group: