Handling planned maintenance notifications using the Azure CLI

Applies to: ✔️ Linux VMs ✔️ Windows VMs ✔️ Flexible scale sets ✔️ Uniform scale sets

You can use the CLI to see when VMs are scheduled for maintenance. Planned maintenance information is available from az vm get-instance-view.

Maintenance information is returned only if there is maintenance planned.

az vm get-instance-view -n myVM -g myResourceGroup --query instanceView.maintenanceRedeployStatus

Output

      "maintenanceRedeployStatus": {
      "additionalProperties": {},
      "isCustomerInitiatedMaintenanceAllowed": true,
      "lastOperationMessage": null,
      "lastOperationResultCode": "None",
      "maintenanceWindowEndTime": "2018-06-04T16:30:00+00:00",
      "maintenanceWindowStartTime": "2018-05-21T16:30:00+00:00",
      "preMaintenanceWindowEndTime": "2018-05-19T12:30:00+00:00",
      "preMaintenanceWindowStartTime": "2018-05-14T12:30:00+00:00"

Start maintenance

The following call will start maintenance on a VM if IsCustomerInitiatedMaintenanceAllowed is set to true.

az vm perform-maintenance -g myResourceGroup -n myVM 

Classic deployments

Important

VMs created through the classic deployment model will be retired on March 1, 2023.

If you use IaaS resources from Azure Service Management, please complete your migration by March 1, 2023. We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.

For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.

If you still have legacy VMs that were deployed using the classic deployment model, you can use the Azure classic CLI to query for VMs and initiate maintenance.

Make sure you are in the correct mode to work with classic VM by typing:

azure config mode asm

To get the maintenance status of a VM named myVM, type:

azure vm show myVM 

To start maintenance on your classic VM named myVM in the myService service and myDeployment deployment, type:

azure compute virtual-machine initiate-maintenance --service-name myService --name myDeployment --virtual-machine-name myVM

Next steps

You can also handle planned maintenance using the Azure PowerShell or portal.