我可以使用 azure vm rest api (PUT) 更改现有虚拟机中的 Os 配置文件吗?

can I change Os profile in existing virtual machine using azure vm rest api (PUT)?

尝试在虚拟机从本地迁移到 Azure 云后更新 OsProfile,因为我需要在 osProfile 下安装 provisionVMAgent? 使用此 API 版本-

参考 Url APi -https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/createorupdate#request-body

PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2019-03-01

{
  "location": "westus",
  "properties": {
    "hardwareProfile": {
      "vmSize": "Standard_D1_v2"
    },
    "storageProfile": {
      "osDisk": {
        "name": "myVMosdisk",
        "image": {
          "uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/{existing-generalized-os-image-blob-name}.vhd"
        },
        "osType": "Windows",
        "createOption": "FromImage",
        "caching": "ReadWrite",
        "vhd": {
          "uri": "http://{existing-storage-account-name}.blob.core.windows.net/{existing-container-name}/myDisk.vhd"
        }
      }
    },
    "osProfile": {
      "adminUsername": "{your-username}",
      "computerName": "myVM",
      "adminPassword": "{your-password}"
    },
    "networkProfile": {
      "networkInterfaces": [
        {
          "id": "/subscriptions/{subscription-id}/resourceGroups/myResourceGroup/providers/Microsoft.Network/networkInterfaces/{existing-nic-name}",
          "properties": {
            "primary": true
          }
        }
      ]
    }
  }
}

邮递员回复 -

{
"error": {
    "code": "PropertyChangeNotAllowed",
    "message": "Changing property 'osProfile' is not allowed.",
    "target": "osProfile"
}

是否可以在 Vm 迁移后更新 Os 配置文件?要么 VM迁移后是否可以在虚拟机中安装provisionVMAgent?

您可以看到 provisionVMAgentthis 的 VM 配置时工作,因此无法在创建 VM 后更新它。

在这种情况下,当您有 created a custom-image VM from an unmanaged generalized os image, you could manually install the Windows VM Agent 时。 Windows Server 2008 R2 及更高版本支持 VM 代理。

可以通过双击 Windows 安装程序文件来安装 VM 代理。对于 VM 代理的自动或无人值守安装,运行 以下命令:

msiexec.exe /i WindowsAzureVmAgent.2.7.1198.778.rd_art_stable.160617-1120.fre /quiet

希望对您有所帮助。