Deleting Azure Virtual Machines

Like other things, there are more than one way to delete Azure Virtual Machines. However with nearly all of them, you have a choice whether you want to delete vhds for the virtual machines or not. Sometimes it may be helpful to retain the disks for later use.

For delete virtual machine from classic portal, use below command:

$name = "mailserver01"
$serviceName = "mailsouthasia"
Remove-AzureVM -Name $name -ServiceName $serviceName

If we need to delete vhds as well, use below command:

$name = "mailserver01"
$serviceName = "mailsouthasia"
Remove-AzureVM -Name $name -ServiceName $serviceName -DeleteVHD

For deleting virtual machines from Azure Resource Management Portal:

$name = "mailserver01"
$resourceGroupName = "mailsouthasia"
Remove-AzureRmVM -Name $name -ResourceGroupName $resourceGroupName -Confirm:$false

You can’t choose to delete vhds using above cmdlet. This is because in Azure Resource Manager, disk is not considered an separate entity. Their is no disk provider in Azure. There is only storage provider. So you can choose to delete storage blob altogether as well.

If you are working with Azure RM portal, you can choose to delete resource group. Deleting a resource group would remove all underlying components such as storage, network, virtual machines, etc.

If you are working with Azure classic portal, you can choose to delete cloud service as well. Deleting a cloud service would delete all virtual machines associated with the service. You’ll need to use the DeleteAll parameter to delete underlying disks when using Remove-AzureService cmdlet.

$serviceName = "mailsouthasia"
Remove-AzureService -ServiceName $serviceName -Force -DeleteAll

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s