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.
How do you remove a VM from a Dedicated Host using the AZ CLI or Powershell?
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?
2 answers
Sort by: Most helpful
-
-
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>