The Ops Community ⚙️

Uday Yadav
Uday Yadav

Posted on

Auto Mount Azure Storage in Windows VM Automatically

Using a external hard drive, where it it super easy to plug it in start working from where you left off isn't the kind of storage strategy one would think off when creating a VM on cloud.

But using it with VM and data you often need can be super useful and time-saver. Here are the steps to get started :

  • Create a FileShare
  • Create FileShare connection script be auto-run at the start of the virtual machine instance and the FileShare be mounted using the same drive letter in VMs.
    • Create the file named script.ps1 in the following folder location
C:\Users\<USER>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Enter fullscreen mode Exit fullscreen mode

With its content as the connection script provided by azure for mounting FileShare, go to the Azure file storage account

FileShare Connect Image

  • Also select the Drive Symbol

Script

Copy the script provided by azure into the script.ps1 file and save it !

In the Same folder create a file startup.bat with the following code :

@ECHO OFF
Powershell.exe -executionpolicy bypass -File  .\script.ps1
Enter fullscreen mode Exit fullscreen mode

And Done ! On every VM or Windows Machine Restart your Storage Account will be Mounted as Z: drive in your OS as the Shell Script will be Auto Executed in Windows

Top comments (0)