At the bottom of this article I have added in a step to allow the new file share to stay connected at next login.
In this article, I am going to show you how to create and map an Azure File Share using the Azure Cloud Shell. But before you create the share here is a bit of information about what Azure Files is.
What is Azure Files
Azure Files is a managed file share that uses the SMB protocol for access and can be accessed from anywhere and on any operating system that supports the SMB protocol. Below is a list from Microsoft of benefits the Azure Files have:
Shared access – Azure File shares support the industry standard SMB protocol, meaning you can seamlessly replace your on-premises file shares with Azure File shares without worrying about application compatibility. Being able to share a file system across multiple machines, applications/instances is a significant advantage with Azure Files for applications that need shareability.
Fully managed – Azure File shares can be created without the need to manage hardware or an OS. This means you don’t have to deal with patching the server OS with critical security upgrades or replacing faulty hard disks.
Scripting and tooling – PowerShell cmdlets and Azure CLI can be used to create, mount, and manage Azure File shares as part of the administration of Azure applications. You can create and manage Azure file shares using the Azure portal and Azure Storage Explorer.
Resiliency – Azure Files has been built from the ground up to be always available. Replacing on-premises file shares with Azure Files means you no longer have to wake up to deal with local power outages or network issues.
You can read more here https://docs.microsoft.com/en-us/azure/storage/files/storage-files-introduction
Create an Azure File Share
Log in to your Azure Subscription by going to https://portal.azure.com
Click on the Cloud Shell button. Top Right.
Hopefully, the PowerShell Cloud Shell should pop up. If the Bash one has, just change it to the PowerShell one.
Create a Storage Account
Now you have to create a new Storage Account ready to hold your new Azure File Share. This can be done using the following PowerShell command. Just make sure you change the -ResourceGroupName to yours.
|New-AzureRMStorageAccount -ResourceGroupName "PixelRobotsLab" -Name "pixelfileshare" -Location "UK South" -SkuName standard_LRS|
For the Sku you can use any of the following:
Standard_LRS – Locally-redundant storage.
Standard_ZRS – Zone-redundant storage.
Standard_GRS – Geo-redundant storage.
Standard_RAGRS – Read access geo-redundant storage.
Premium_LRS – Premium locally-redundant storage.
Create the File Share
So you have the storage account, but you need the Storage Access Key before you can actually create the share. Use the following PowerShell command to get this. Just remember to change the Resource Group and Storgae Account to yours.
|Get-AzureRmStorageAccountKey -ResourceGroupName "PixelRobotsLab" -AccountName "pixelfileshare"|
Copy the storage Key to the clipboard.
Now you can actually create the file share. To do this use the following PowerShell command. Just make sure you change the -NewAzureStorageContext to your Storage Accounts name and use your own Storage Access Key
|$SAC = New-AzureStorageContext "pixelfileshare" "ydfisEVGXkmG/CQ9DyqSiyr/yPk/7RTopTjmd7vivgnyx+/n14pnNGi3ZpXqA+98vjI5EHe1iCBh8lufRVwdrg=="|
|New-AzureStorageShare "pixelshare" -Context $SAC|
You have now created a file share using the default quota of 5GB.
In the Azure Portal, you will see something like the image below.
How To Map the Share
Now that you have created an Azure File Share its time you mapped it to your Windows device. To do this open PowerShell on your Windows device and use the following PowerShell command.
|net use P: \\pixelfileshare.file.core.windows.net\pixelshare "ydfisEVGXkmG/CQ9DyqSiyr/yPk/7RTopTjmd7vivgnyx+/n14pnNGi3ZpXqA+98vjI5EHe1iCBh8lufRVwdrg==" /user:Azure\pixelfileshare|
You can use the get-psdrive to show your mapped drive.
If you open up file explorer you will be able to see your mapped drive and you can use it in the same way as any mapped drive.
In the Azure Portal, you will be able to see any files you have in the share.
Keep your drive connected
Open PowerShell as the user the drive is mapped to and enter the following command. Make sure you change the details to match your share details and key.
|cmdkey /add:pixelfileshare.file.core.windows.net /user:AZURE\pixelshare /pass:ydfisEVGXkmG/CQ9DyqSiyr/yPk/7RTopTjmd7vivgnyx+/n14pnNGi3ZpXqA+98vjI5EHe1iCBh8lufRVwdrg==|
Now on next reboot, your drive will reconnect.
If you have any issues mapping the drive. Make sure your firewall is not blocking SMB.
I hope you found this article helpful. If you have any questions please leave a comment or reach out to me via social media or email.