Search Posts

AZ CLI: How to delete and re-deploy a VM from VHD (unmanaged disk)

You should be able to use the built-in CLI on the Azure portal, for more details on how to use it, please check: Azure Cloud Shell (quickstart)

If not, you can always install it locally on your workstation or also using docker, for details, please follow the steps described here: Install the Azure CLI

For the steps to work properly, please, make sure you are logged into the Azure CLI:
<tt>az login</tt>

NOTE: You will get a code which you then have to type in the box using the link https://aka.ms/devicelogin and proceeding with logging in to your Azure account. Once you go through that you can go back to the prompt.

In this example, the following variables will be used:

Resource Group: ARMGROUP
Original VM Name: LinuxVM
Location: southcentralus
NIC Name: LinuxVM-NIC
VHD URI: https://ARMSTORAGE.blob.core.windows.net/vhds/linuxvm.vhd

If you want to keep some information from the VM before deleting:
<tt>az vm show -g ARMGROUP -n LinuxVM &gt; ORIGINAL_VM.txt</tt>

Deleting a VM on ARM using the CLI:
<tt>az vm delete -g ARMGROUP -n LinuxVM</tt>

Recreating the VM from the Original VHD:
<tt>az vm create -g ARMGROUP -n LinuxVM --nics LinuxVM-NIC --use-unmanaged-disk --attach-os-disk https://storageaccount.blob.core.windows.net/vhds/linuxvmoriginal2017.vhd --size Standard_D1_V2 -l southcentralus --os-type Linux</tt>

After the command is executed you should be able to see the VM on the Azure Portal. You might need to re-enable diagnostics in the particular VM.

Leave a Reply

Your email address will not be published. Required fields are marked *