Freigeben über


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:
az login

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:
az vm show -g ARMGROUP -n LinuxVM > ORIGINAL_VM.txt

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

Recreating the VM from the Original VHD:
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

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.