Quickstart: Create and use an SMB Azure file share
Article
Azure Files is an 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 trial account before you begin.
If you don't have an Azure subscription, create a trial account before you begin.
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. You also need to run Login-AzAccount -Environment AzureChinaCloud 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> -Environment AzureChinaCloud.
Prerequisites
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.
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 China East 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 China East 2 location:
export resourceGroupName="myResourceGroup"
region="chinaeast2"
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 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.
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 "../YourDrive/"
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"
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 on your drive. In the following example, you create and then upload the file:
cd ../yourdrive/
date > SampleUpload.txt
az storage file upload \
--account-name $storageAccountName \
--share-name $shareName \
--source "SampleUpload.txt" \
--path "myDirectory/SampleUpload.txt"
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.
# 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.
You can use the az storage file download command to download a copy of the file that you uploaded:
# 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.