通过ARM模板在Azure Windows上运行powershell命令

问题描述:

我正尝试通过正在旋转虚拟机的ARM模板将数据磁盘安装到Azure上的Wondows Vm上。这是我的ATM资源通过ARM模板在Azure Windows上运行powershell命令

{ 
     "name": "[parameters('virtualMachineName')]", 
     "type": "Microsoft.Compute/virtualMachines", 
     "apiVersion": "2016-04-30-preview", 
     "location": "[parameters('location')]", 
     "dependsOn": [ 
      "[concat('Microsoft.Network/networkInterfaces/', parameters('networkInterfaceName'))]" 
     ], 
     "tags": { 
      "Busuness Group": "[parameters('busunessGroup')]", 
      "Role": "[parameters('role')]" 
     }, 
     "properties": { 
      "osProfile": { 
       "computerName": "[parameters('virtualMachineName')]", 
       "adminUsername": "[parameters('adminUsername')]", 
       "adminPassword": "[parameters('adminPassword')]", 
       "windowsConfiguration": { 
        "provisionVmAgent": "true" 
       } 
      }, 
      "hardwareProfile": { 
       "vmSize": "[parameters('virtualMachineSize')]" 
      }, 
      "storageProfile": { 
       "imageReference": { 
        "publisher": "microsoft-ads", 
        "offer": "standard-data-science-vm", 
        "sku": "standard-data-science-vm", 
        "version": "latest" 
       }, 
       "dataDisks": [ 
        { 
         "lun": 0, 
         "createOption": "Empty", 
         "caching": "None", 
         "managedDisk": { 
          "storageAccountType": "Premium_LRS" 
         }, 
         "diskSizeGB": "[parameters('dataDiskSizeGB')]", 
        } 
       ] 
      }, 
      "networkProfile": { 
       "networkInterfaces": [ 
        { 
         "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]" 
        } 
       ] 
      } 
     }, 
     "plan": { 
      "name": "standard-data-science-vm", 
      "publisher": "microsoft-ads", 
      "product": "standard-data-science-vm" 
     }, 
     "resources": [ 
      { 
       "type": "extensions", 
       "name": "CustomScriptExtension", 
       "apiVersion": "2015-06-15", 
       "location": "[resourceGroup().location]", 
       "dependsOn": [ 
        "[parameters('virtualMachineName')]" 
       ], 
       "properties": { 
        "publisher": "Microsoft.Compute", 
        "type": "CustomScriptExtension", 
        "typeHandlerVersion": "1.8", 
        "autoUpgradeMinorVersion": true, 
        "settings": { 
         "fileUris": ["https://paste.fedoraproject.org/paste/FMoOq4E3sKoQzqB5Di0DcV5M1UNdIGYhyRLivL9gydE=/raw"] 
        } 
       } 
      } 
     ] 
    } 

它失败,以下错误

{ 
    "code": "VMExtensionProvisioningError", 
    "message": "VM has reported a failure when processing extension 'CustomScriptExtension'. Error message: \"Invalid Configuration - CommandToExecute is not specified in the configuration; it must be specified in either the protected or public configuration section\"." 
    } 

我也试过路过的命令直接

"settings": { 
    "commandToExecute": "Get-Disk |Where partitionstyle -eq ‘raw’ | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel “Data” -Confirm:$false" 
    } 

都没有工作。我在这里做错了什么?

所以,你需要显式调用PowerShell来使用PowerShell,就像在examples

"commandToExecute": "[concat('powershell -command ', variable('command'))]" 

您可以尝试直接粘贴您的命令,但由于所有就不能正确解析引号,所以把你的命令保存为一个变量并且像这样连接。

+0

我想这https://paste.fedoraproject.org/paste/Om8O6NGsyzwRk0M4XTuWl15M1UNdIGYhyRLivL9gydE=/raw这给了我错误https://paste.fedoraproject.org/paste/YQFco0QpiskdoIv3EvQ9VF5M1UNdIGYhyRLivL9gydE=/raw – roy

+0

好,你至少有2错误:“diskMountCommand”:“Get-Disk | Where partitionstyle -eq'raw'| Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel'Data'-Confirm :$ false“'尝试这一个 – 4c74356b41

+0

同样的错误https://paste.fedoraproject.org/paste/fBIyTQecA5VsfDDaqs7NWl5M1UNdIGYhyRLivL9gydE= – roy