none
Not able to map a fileshare in a storage account to a network drive in a vm using custom powershell script using the net use command

    Question

  • Hi,

    I am trying to provision a windows vm with a custom script extension to map a network drive of the vm to a fileshare of a storage account using the Azure arm json template. I have included the net use command in a powershell script and using the following command to execute that script on the vm during its provisioning. My drive gets created with the specified name but it is disconnected and shows "This network connection does not exist".Please help me with this as i m trying to provision a vm with the mapped drive using json arm template.

    command:

     {
      "type": "Microsoft.Compute/virtualMachines/extensions",
      "name": "[concat(variables('vmName'),'/', variables('extensionName'))]",
      "apiVersion": "2015-06-15",
      "location": "[resourceGroup().location]",
      "dependsOn": [
      "[concat('Microsoft.Compute/virtualMachines/', variables('vmName'))]"
      ],
       "properties": {
           "publisher": "Microsoft.Compute",
           "type": "CustomScriptExtension",
           "typeHandlerVersion": "1.7",
           "autoUpgradeMinorVersion":true,
           "settings": {
               "fileUris": [
               "https://varsharani.blob.core.windows.net/eclipsedeploy/fileshare.ps1"
           ],
           "commandToExecute": "powershell -ExecutionPolicy unrestricted -File fileshare.ps1"
         }
       }

    Tuesday, October 25, 2016 10:45 AM

All replies

  • As far as I can tell, in order for you to access the mapped drive in this scenario you would need to store the credentials (i.e. the storage account name and key) in the Credential Manager store of the user account you are using to log on to the VM

    hth
    Marcin

    Tuesday, October 25, 2016 11:21 AM
  • when i add the credentials manually in the credential manager i still get the drive disconnected even after restart.I have also tried to add the credentials in the powershell script and provided the script as the custom script extension in the arm json template.

    the script file contains the following commands:

    cmdkey /add:<storage account url> /user:<storageaccountname>/pass:<storage account key>
    net use r: \<storage account url>\<filesharename> /u:<storageaccountname> <storageaccountkey>

    Friday, October 28, 2016 10:08 AM
  • You need to store the credentials (i.e. the storage account name and key) in the Credential Manager store of the user account you are using to log on to the VM

    As far as I can tell, you are storing the credentials in the security context of the system account that is being used to provision the VM

    hth
    Marcin

    Friday, October 28, 2016 10:48 AM
  • Hi,

    how can you store the credentials in the Credential Manager store of the user account (via PS commands) specifying a particular user (the user account used to log on the VM in this case)?


    • Edited by Azul75 Thursday, December 14, 2017 9:17 PM
    Thursday, December 14, 2017 9:16 PM