In this tutorial, we will learn How to remove an Azure Virtual Machine (VM)
How to remove an Azure Virtual Machine (VM) : Step by Step Guide.
You can remove/delete an Azure Virtual machine (VM) using the Azure portal, Azure CLI and Powershell Script. Let’s go through each one of the available options
#Remove an Azure Virtual Machine through Azure portal
Step 1: Logon to the Azure Portal.
Log on to https://portal.azure.com/ and navigate to your Azure subscription under which you need to delete the Azure VM.
Step 2: Under Azure Services Select Virtual Machines.
Step 3: Select the Virtual Machine which you want to delete.
- Select the virtual machine from the list of virtual machines as per your environment.
- First Stop the virtual machine by selecting the Stop option on top right and click on yes to confirm.
- Navigate to the three dots on the top right of the screen as shown below
- From the drop-down select Delete.
Step 4: Confirm the deletion
- Before deletion, a new screen will pop up which will ask for your confirmation.
- Type ‘yes‘ to confirm and click on Delete
#Remove an Azure Virtual Machine from Azure CLI
az vm delete
You can also use the Azure CLI cmdlet to delete an Azure virtual machine.
Following is the Syntax for the same.
az vm delete [--force-deletion] [--ids] [--name] [--no-wait] [--resource-group] [--subscription] [--yes]
az vm delete -g MyResourceGroup -n MyVm --yes
- -g : stands for the resource group name
- -n : stands for your virtual machine name
- if you use the option –yes at the end it will delete the VM without asking for confirmation
Let’s see an example
Step 1: Logon to Azure CLI
Step 2: Run the azure VM deletion cmdlet
In the below example we are deleting an Ubuntu Virtual machine.
As we have not used the –yes option at the end it will ask for confirmation. Type y to confirm.
Your Azure VM will be deleted.
# Using “Remove-AzVM” Power Shell command.
You can also use PowerShell to delete a virtual machine using the Remove-AzVM command.
Following is the Syntax for the Remove-AzVM PowerShell command.
Syntax
Remove-AzVM [-Name] <String> [-Force] [-NoWait] [-ResourceGroupName] <String> [-AsJob] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Example :
Remove-AzVM -ResourceGroupName "ResourceGroup11" -Name "VirtualMachine07"
To delete all the resources within a resource group using the below syntax
Syntax
Remove-AzResourceGroup [-Name] <String> [-Force] [-AsJob] [-ApiVersion <String>] [-Pre] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Example
az vm delete --ids $(az vm list -g DemoResourceGroup --query "[].id" -o tsv)
We hope this tutorial on How to remove an Azure Virtual Machine was helpful.
Related articles :
How to fix Because of Protocol Error Code 0x112d
You are not eligible for an Azure Subscription : (1 Stop Complete Guide )