Delete a Virtual Machine

This document guides you through the process of deleting a virtual machine (VM) in Azure. Deleting a VM is a permanent action and cannot be undone. All associated resources, such as disks and network interfaces, may also be deleted depending on your configuration.

Important: Before proceeding, ensure you have backed up any critical data stored on the virtual machine. Once a VM is deleted, its data is irrecoverable.

Methods for Deleting a VM

You can delete a virtual machine using the Azure portal, Azure CLI, or Azure PowerShell.

1. Using the Azure Portal

The Azure portal provides a user-friendly graphical interface to manage your Azure resources.

Navigate to the Virtual Machines blade: Log in to the Azure portal. In the search bar at the top, type "Virtual machines" and select it from the search results.
Select the VM to delete: In the Virtual machines list, click on the name of the virtual machine you want to delete.
Initiate deletion: On the virtual machine's overview page, click the Delete button located at the top of the page.
Confirm deletion: A confirmation dialog will appear. Review the details and type the name of the virtual machine in the confirmation field to confirm. Click Delete to proceed.
Note: Depending on your VM's configuration, deleting the VM might prompt you to delete associated resources like disks, network interfaces, or public IP addresses. You can choose which resources to delete.

2. Using Azure CLI

The Azure Command-Line Interface (CLI) is a powerful tool for managing Azure resources from your terminal.

First, ensure you are logged in to your Azure account:

az login

Then, use the az vm delete command. Replace <resource-group-name> with the name of the resource group containing your VM, and <vm-name> with the name of your virtual machine.

az vm delete --resource-group <resource-group-name> --name <vm-name> --yes

The --yes flag automatically confirms the deletion without prompting.

To delete the VM and its associated resources (like disks), you might need to use additional commands or parameters depending on how the VM was created and configured.

3. Using Azure PowerShell

Azure PowerShell provides cmdlets for managing Azure resources.

First, ensure you are logged in to your Azure account:

Connect-AzAccount

Then, use the Remove-AzVM cmdlet. Replace <resource-group-name> with the name of the resource group, and <vm-name> with the name of your virtual machine.

Remove-AzVM -ResourceGroupName <resource-group-name> -Name <vm-name> -Force

The -Force parameter automatically confirms the deletion.

Similar to the CLI, managing associated resources might require additional cmdlets like Remove-AzDisk or Remove-AzPublicIpAddress.

After Deletion

Once a VM is deleted, it will no longer appear in your Azure portal or be accessible. You will stop being billed for the VM's compute resources. However, you may continue to be billed for associated storage resources (like unattached disks) if they were not deleted.

Always verify that all desired resources have been deleted to avoid unexpected costs. Review your resource group or subscription after deletion.