How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync

4 Min. Read

In this guide, I will show you how to mount a drive and persist an Azure File share connection with Windows, so even if you reboot your computer the connection is persisted.

Updated – 06/05/2019 – Global mapping support for Windows 10, version 1709 / Windows Server 2019 or later


Azure File storage offers shared storage for applications using the standard SMB 3.0 protocol. Microsoft Azure virtual machines and cloud services can share file data across application components via mounted shares, and on-premises applications can access file data in a share via the File storage API.

Applications running on Azure virtual machines can mount a File storage share to access file data, just as a desktop application would mount a typical SMB share. Any number of Azure virtual machines or roles can mount and access the File Storage share simultaneously.

Microsoft also introduced the Azure File Sync service which is a new service that will allow you to centralize your file shares in Azure Files, whilst maintaining the compatibility of an on-premises file server with all the flexibility and performance benefits provide. Any protocol installed on the Windows Server can access the Azure file share, including SMB, NFS, and FTPS. For more information about Azure File Sync and how to get started, please check the following step-by-step guide.

Since a File storage share is a standard SMB 3.0 file share, applications running in Azure can access data in the share via file I/O APIs. Developers can, therefore, leverage their 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 the administration of Azure applications.

Mount and Persist an Azure file share with Windows

Now if you have been working with file shares for quite some time, you have probably come across a situation where you map a drive, and then reboot your computer to find out that the drive disappears…

If this is the case, please read on!

Store Azure storage account credentials

To get the mapped drive to persist, we should first store the Azure storage account key (credentials) using the cmdkey utility. Cmdkey is a utility that helps you to create, list, and delete stored usernames and passwords.

Open a normal PowerShell window (not as Administrator) and type the following command (make sure to change the storage account name, username and password):

Invoke-Expression -Command "cmdkey /add:<storageaccountname> /user:<storageaccountname> /pass:<storagekey>"

How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 2

If you open Windows Credentials in Credential Manager, you can see that the credentials are stored now as persistence.

How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 3

Mount Azure File Share Drive

Once the credentials are persisted, you can mount the drive now by specifying the Azure File Share full UNC path but without providing credentials. To do so, open a normal PowerShell window (not as Administrator) and type the following command:

New-PSDrive -Name Z -PSProvider FileSystem -Root "\\\filesharename" -Persist

How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 4

Now every time you reboot your machine, the mapped drive, in this case, Z drive is always persisted as shown in the following screenshot.

How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 5

That’s it there you have it!

There’s more…

Please note that Windows Credentials are persisted in the same user context, in other words, if you logged in with a different user account on the same machine, you will notice that the credentials are not persisted. You need to follow the same steps as described above for every user who wants to use the UNC path after each login.

If you have an application that wants to access the UNC path in Azure files, what you can do is to set up the application with a deployment service to run as the (NT Authority\System) account instead of a user account. In this case, you need to download the PsExec tool from Microsoft, and then use the Cmdkey utility as described above to add the credentials. In this way, you can cache the credentials for the remote file share using the Windows Credential Manager.

To add the credentials when the target account is SYSTEM, you need to open a PowerShell session as Administrator, and then type the following commands (make sure to change the storage account name, file share name, username, and password):

How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 6

.\PsExec.exe -s -accepteula -nobanner cmdkey /add:<storageaccountname> /user:<storageaccountname> /pass:<storagekey>

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

Net use Z: "\\<storageaccountname>\filesharename" /persistent:yes


How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync 7

Now every time you reboot your machine, your application will always have access to the file share using the (NT Authority\System) account instead of the user account.

Windows 10 1709 and Windows Server 2019

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

There are two caveats that you want to be aware of. In December 2018, Microsoft released an update (KB4469342) to addresses an important issue that causes mapped drives to fail to reconnect after starting and logging onto a Windows device. However, this fix still only applies to regular user accounts under the user context scenario as described above. It would have no effect for mapped drives created by service accounts such as SYSTEM or NetworkService. In other words, every time you reboot your machine, the SMB connection will not reconnect. If you want to persist a connection for file share under SYSTEM or NetworkService account, you need to run a script at startup as described in this article.

The good news is, that starting with Windows 10 version 1709, or Windows Server 2019 or newer, you can use the new SMB Global mapping functionality to create a ‘global’ mapping that can be made accessible to the desired accounts.

To persist an SMB connection with Azure File Share under SYSTEM account, you need to open a PowerShell session as Administrator, and then run the New-SMBGlobalMapping cmdlet as shown below (make sure to change the storage account name, file share name, username, and password):

$cred = Get-Credential
New-SmbGlobalMapping -RemotePath <storageaccountname> -Credential $cred -LocalPath Z: -FullAccess @( "NT AUTHORITY\SYSTEM", "NT AUTHORITY\NetworkService" ) -Persistent $true -RequirePrivacy $true

These mappings can be accessed by any account that satisfies the ACL constructed from the -FullAccess and -DenyAccess parameters. However, for lower versions of Windows, the Startup script is the best solution.


It’s very important to follow the two steps described in this article because if you mount the drive first by specifying the credentials, and then store the storage account key, the drive won’t actually persist.

Azure Files and Azure File Sync give you the ability to share files without the need to deploy the underlying server infrastructure provides several benefits when building an Azure-based application.

Hope this helps!

Thank you for reading my blog.

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

-Charbel Nemnom-

Related Posts


(Solution) Azure File Sync – Server Endpoint Provisioning Failed – Error 2134376427

Holiday Giveaway From Vembu Technologies Before the End of the Year! @vembutech


7 thoughts on “How To Mount and Persist an Azure File Share with Windows #AzureFiles #AzureFileSync”

Leave a comment...

  1. When I try to mount such a Azure file share, I get an error:
    “New-PSDrive : The network resource type is not correct”

    If I remove “-Persist” then the operation will seemingly succeed, it will list the new drive with ‘Get-PSDrive’, If I want to create the same drive with New-PSDrive it will throw an error that it is already exists, yet, I the drive does not exist, I can’t change to it, and even ‘Test-Path Z’ says that the drive does not exist.

  2. What is the error that are you getting?
    Did you try to run the New-PSDrive under admin privilege.
    Or if you run it under user context, please try to add -Credential parameter “XXXXX\Admin”


  3. Well it looks like your psexec examples do not work on Windows Server 2016 Datacenter.

    I ran an admin PowerShell.
    I run the cmdkey and it says “Credential added successfully.” but I go into Credential Manger and it’s not there. I run the net use command it says “The command completed successfully”. But File Explorer shows the mapping with “invalid credentials”. When I do a “cmdkey /list” the credentials aren’t there.
    I run a “whoami” and it shows I’m running as my not NT/System.

    I then tried running:
    .\PsExec.exe -s -accepteula -nobanner powershell
    Typeed “whoami” I get:
    nt authority\system

    Great I’m who I need to be.
    So I run the same psexec commands again and still nothing.

    Any thoughts?

  4. Nice write up Charbel!

    I see the credential in credential manager, but when I run the New-PSDrive with the -persist switch,

    New-PSDrive -Name Z -PSProvider FileSystem -Root “\\\employee-information” -Persist

    I get the error: “New-PSDrive : The parameter is incorrect”

    Without the -Persist switch, it works but without mapping I can’t access via file explorer or share out to users

    I also tried to run:

    New-PSDrive -Name Z -PSProvider FileSystem -Root “\\\employee-information” -Persist -Credential “Azure\sawallazfiles”

    After entering the key at the prompt, I still get the error: “New-PSDrive : The parameter is incorrect”

    Any idea what it could be or something else to try?

    Thanks for your help!


  5. I had to disable NTLMv1 as well (besides disabling SMBv1 and enable SMBv2 which is the same stack as SMBv3) to get the Azure example working, and now it is fine.

Let me know what you think, or ask a question...

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe to Stay in Touch

Never miss out on your favorite posts and our latest announcements!

The content of this website is copyrighted from being plagiarized!

You can copy from the 'Code Blocks' in 'Black' by selecting the Code.

Please send your feedback to the author using this form for any 'Code' you like.

Thank you for visiting!