How do you remove a VM from a Dedicated Host using the AZ CLI or Powershell?

Rahul A 1 Reputation point
2022-09-20T07:32:58.597+00:00

I have a bunch of VMs on a number of dedicated hosts, in host groups.
Instead of stopping each VM & removing from the Portal, I want to automate this activity.

I've searched around and I can't find any commands that do something equivalent to "Remove from host".

Could someone point me to the right direction?

Azure Dedicated Host
Azure Dedicated Host
An Azure service that provides a dedicated physical server to host Azure virtual machines for Windows and Linux.
47 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sam Cogan 10,157 Reputation points MVP
    2022-09-20T11:21:37.237+00:00

    VM's on Dedicated Hosts are just the same as normal VM's and you can use the same Azure Powershell commands to manage them. You can use the Remove-AzVm command to remove the VM. If you want to create a VM with PowerShell you can use the new-azvm command, but for this you need to specify the HostId parameter to ensure it is added to the right host, this is not required for deletion.


  2. Rahul A 1 Reputation point
    2022-10-11T23:36:40.757+00:00

    I worked it out:

    1) Stop VM

    az vm deallocate --resource-group <resource group name> --name <vm name>

    2) Go to Host --> Select the VM --> Click "Remove from Host"

    az vm update --resource-group <resource group name> --name <vm name> --set host.id=null

    3) Start the VM

    az vm start --resource-group <resource group name> --name <vm name>

    0 comments No comments