Introduction

So this one kept me busy for a while. I recently needed to mount an Azure File share on a Windows server in a different subscription. As such the usual process of using a system-assigned identity for authorization was not available to me.

If you google the problem you will find multiple solutions calling for the creation of a logon script that executes during user sign-in and then mounts the drive. This is not a great solution as it requires interactive login. Not to mention if you have services running under system accounts this is not going to do what you want.

If only you could mount a share like you do in Linux so that it's globally accessible (permissions allowing of course).

Enter the PowerShell command: New-SmbGlobalMapping

Assumptions

  • You have already created the storage container and a file share. Note, I say file share here. Blob Storage and File Shares are not the same things.
  • You have gone to your file share and clicked on the connect button and copied the username and password
  • The storage container is accessible via your current network

The Solution

The PowerShell command we will use is called New-SmbGlobalMapping.
Details can be found here.

$secpasswd = ConvertTo-SecureString 'password' -AsPlainText -Force;
$creds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd);
New-SmbGlobalMapping -RemotePath '\\sharename.file.core.windows.net\sharefolder' -Persistent $true -Credential $creds -LocalPath G:;

The above command will mount the shareholder as the G: drive.
Change the values for:

  • 'password'
  • 'username'
  • 'sharename'
  • 'sharefolder'

The best is it is available at system level. Meaning any user/system account will now have access to this folder