Just a short quick tip for connecting to Azure File Share. If you haven’t worked with Azure File Shares in a while you may read up on the documentation for working with Azure File Shares https://docs.microsoft.com/en-us/azure/storage/files/storage-how-to-use-files-windows, and begin to read through the documentation and the script snippets required to map the drive.
All of this information is still valid, but there is a nice quick way to get the connection script information available from the Azure Portal.
Just simply browse to the Azure File Share, and there is a “Connect” button. This button will open up menu that will show you all of the required commands to map and persist the Azure File Share.
It will then show you the connection options that you can easily copy and paste with all of the required storage account details and key. Please do not save this script as it contains the storage account key, and this should be used as a one time setup only.
One thing to be aware of is that even though in the commands that are generated from the portal include the -persist switch for the New-PsDrive cmdlet. The mapped drive will not automatically mount on each sign-on unless the storage credential is persisted using the CMDKEY command. That script is also available on the previous link.
$resourceGroupName = "<your-resource-group-name>"
$storageAccountName = "<your-storage-account-name>"
# These commands require you to be logged into your Azure account, run Login-AzureRmAccount if you haven't
# already logged in.
$storageAccount = Get-AzureRmStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName
$storageAccountKeys = Get-AzureRmStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageAccountName
# The cmdkey utility is a command-line (rather than PowerShell) tool. We use Invoke-Expression to allow us to
# consume the appropriate values from the storage account variables. The value given to the add parameter of the
# cmdkey utility is the host address for the storage account, <storage-account>.file.core.windows.net for Azure
# Public Regions. $storageAccount.Context.FileEndpoint is used because non-Public Azure regions, such as sovereign
# clouds or Azure Stack deployments, will have different hosts for Azure file shares (and other storage resources).
Invoke-Expression -Command "cmdkey /add:$([System.Uri]::new($storageAccount.Context.FileEndPoint).Host) " + `