Quickstart: Create and use an SMB Azure file share
Alt
Azure Files is Microsoft's easy-to-use cloud file system. You can mount SMB Azure file shares in Windows, Linux, and macOS operating systems. This article shows you how to create an Azure file share using either the Azure portal, Azure CLI, or Azure PowerShell.
Applies to
This Quickstart only applies to SMB Azure file shares. Standard and premium SMB file shares support locally redundant storage (LRS) and zone-redundant storage (ZRS). Standard file shares also support geo-redundant storage (GRS) and geo-zone-redundant storage (GZRS) options. For more information, see Azure Files redundancy.
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.
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 or command block. Selecting Try It doesn't automatically copy the code or command 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 use Azure Cloud Shell:
Start Cloud Shell.
Select the Copy button on a code block (or command block) to copy the code or command.
Paste the code or command 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 or command.
If you'd like to install and use PowerShell locally, you'll need the Azure PowerShell module Az version 7.0.0 or later. We recommend installing the latest available version. 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 multifactor 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're 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 other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension 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), which 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 Storage accounts.
Select + Create 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.
If you want to create a new resource group, select Create new and enter a name such as myexamplegroup.
Under Instance details, provide a name for the storage account. You might need to add 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'll use it later.
In Region, select the region you want to create your storage account in.
In Primary service, select Azure Files.
In Performance, keep the default value of Standard.
In Redundancy, select Locally redundant storage (LRS).
Select Review + create to review your settings. Azure will run a final validation.
When validation is complete, select Create. You should see a notification that deployment is in progress.
When you see a notification that your deployment is complete, select Go to resource.
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.
In the service menu, under Data storage, select File shares.
On the menu at the top of the File shares page, select + File share. The New file share page drops down.
In Name, type myshare. File share names must be all lower-case letters, numbers, and single hyphens, and must begin and end with a lower-case letter or number. The name can't contain two consecutive hyphens. For details about naming file shares and files, see Naming and Referencing Shares, Directories, Files, and Metadata.
Leave Transaction optimized selected for Access tier.
Select the Backup tab. By default, backup is enabled when you create an Azure file share using the Azure portal. If you want to disable backup for the file share, uncheck the Enable backup checkbox. If you want backup enabled, you can either leave the defaults or create a new Recovery Services Vault in the same region and subscription as the storage account. To create a new backup policy, select Create a new policy.
Select Review + create and then Create to create the Azure file share.
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 100 TiB.
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 100 TiB.
To create a new directory named myDirectory at the root of your Azure file share, use the az storage directory create command:
Note
If you don't provide credentials with your commands, Azure CLI will query for your storage account key. You can also provide your storage account key with the command by using a variable such as --account-key $storageAccountKey or in plain text such as --account-key "your-storage-account-key-here".
First, you need to create or select a file to upload. Do this by whatever means you see fit. When you've decided on the file you'd like to upload, follow these steps:
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 the 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 \
--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 \
--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 cmdlet 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 \
--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 deployed inside the resource group.
If there are locks on the storage account, you'll need to remove them first. Navigate to the storage account and select Settings > Locks. If any locks are listed, delete them.