4 min. Read

In this guide, I will show you how to install the drive and maintain the Azure File share connection with Windows, so even if the computer is restarted, the connection will continue.

Updated – May 6, 2019 – General mapping support for Windows 10, version 1709 / Windows Server 2019 or later

Azure File Storage provides shared storage for applications that use the standard SMB 3.0 protocol. Microsoft Azure computers and cloud services can share file information between application components through connected shares, and on-premises applications can access file information through the File Storage API.

Applications running on Azure virtual machines can attach a file storage portion to file information, just as a desktop application attaches a typical SMB share. Any number of Azure virtual machines or roles can mount and use file storage sharing at the same time.

Microsoft also introduced Sync Azure files a service that is a new service that allows you to centralize your file sharing with Azure Files while maintaining the compatibility of your local file server with all the flexibility and performance benefits it offers. Any protocol installed on Windows Server can use Azure file sharing, including SMB, NFS, and FTPS. To learn more about Azure File Sync and how to get started, check the following step-by-step instructions.

Because file storage sharing is a standard SMB 3.0 file sharing, applications running in Azure can access the data in the share through the file’s I / O APIs. Thus, developers can leverage existing code and skills to migrate existing applications. IT professionals can use PowerShell cmdlets to create, mount, and manage file storage shares as part of managing Azure applications.

If you’ve been working on file sharing for a while, you’ve probably encountered a situation where you mapped a drive and then restarted your computer to find out that the drive was missing …

If so, read on!

Save the Azure storage account credentials

For the merged drive to remain valid, we must first save the Azure storage account key (credentials) using the cmdkey utility. Cmdkey is a utility that allows you to create, list, and delete stored usernames and passwords.

Open a standard PowerShell window (not as an administrator) and type the following command (be sure to change the storage account name, username, and password):

Invoke-Expression -Command "cmdkey /add:<storageaccountname>.file.core.windows.net /user:<storageaccountname> /pass:<storagekey>"

If you open Windows logon information in Identification Manager, you will see that the credentials are now saved as persistence.

Installing and Maintaining Azure File Sharing with Windows #AzureFiles #AzureFileSync 2

Install Azure File Share Drive

Once the credentials are preserved, you can now install the drive by specifying the full UNC path for Azure File Share. but without issuing proxies. To do this, open a normal PowerShell window (not as an administrator) and type the following command:

New-PSDrive -Name Z -PSProvider FileSystem -Root "storageaccountname.file.core.windows.netfilesharename" -Persist

Installing and Maintaining Azure File Sharing with Windows #AzureFiles #AzureFileSync 3

Now, every time you restart your machine, the connected drive, in this case, the Z drive will always remain in effect according to the following screenshot.

Installing and Maintaining Azure File Sharing with Windows #AzureFiles #AzureFileSync 4

That’s what you have!

Note that the Windows logon information remains on the same user connection, that is, if you log on with a different user account on the same machine, you will find that the logon information is not stored. You must follow the same instructions as described above for each user who wants to use the UNC path after each login.

If you have an application that wants to use the UNC path in Azure files, you can configure the application to configure the Deployment Service to work (NT Authority System) account instead of a user account. In this case, you have to download the PsExec tool From Microsoft and then use Cmdkey utility as described above to add login information. This way, you can use Windows to cache remote data sharing credentials Identification Manager.

Add credentials when the destination account is SYSTEM, you must open a PowerShell session as an administratorand then type the following commands (be sure to change the storage account name, file share name, user name, and password):

Installing and maintaining an Azure file share with Windows #AzureFiles #AzureFileSync 5

.PsExec.exe -s -accepteula -nobanner cmdkey /add:<storageaccountname>.file.core.windows.net /user:<storageaccountname> /pass:<storagekey>

.PsExec.exe -s -accepteula -nobanner cmd.exe

Net use Z: "<storageaccountname>.file.core.windows.netfilesharename" /persistent:yes

Exit

Installing and Maintaining Azure File Sharing with Windows #AzureFiles #AzureFileSync 6

Every time you restart your computer, your app will always have access to share files (NT Authority System) account instead of a user account.

The steps above are based on Windows Server 2016 or earlier, including Windows 10 version 1703 or earlier.

There are two caveats you want to be aware of. In December 2018, Microsoft released update (KB4469342) fixes an important issue that causes connected drives to fail to connect after you start and log on to a Windows device. However, this fix still applies only to regular user accounts in the user context scenario described above. It would have no effect on combined drives that have created service accounts, such as SYSTEM or Online service. In other words, every time you restart your machine, the SMB connection will not re-establish. If you want to keep connected from the file sharing section SYSTEM or Online service account, you must run a script at startup as described in this article.

The good news is that from Windows 10 1709 or Windows Server 2019 or later, you can use the new one SMB Global mapping function create a ‘global’ inventory that can be made available to desired accounts.

Stay in SMB connection under Azure File Share SYSTEM account, you must open a PowerShell session as an administratorand then run New SMBGlobalMapping cmdlet as shown below (be sure to change the storage account name, file share name, username, and password):

$cred = Get-Credential
New-SmbGlobalMapping -RemotePath <storageaccountname>.file.core.windows.net -Credential $cred -LocalPath Z: -FullAccess @( "NT AUTHORITYSYSTEM", "NT AUTHORITYNetworkService" ) -Persistent $true -RequirePrivacy $true

These mappings can be accessed by any account that fills the ACL generated from the ACL -Full access and -Block access parameters. In Windows versions Startup script is the best solution.

It is very important to follow the two steps described in this article, because if you install the drive by first specifying the credentials and then saving the storage key, the drive is definitely not valid.

Azure Files and Azure File Sync allow you to share files without having to deploy the underlying server infrastructure, offering several benefits for building an Azure-based application.

Hopefully this will help!

__
Thanks for locking my blog.

If you have any questions or feedback, please leave a comment.

-Charbel Nemnom-

LEAVE A REPLY

Please enter your comment!
Please enter your name here