This post is about the way to unregister and register VMs from/to ESXi hosts using commands (Local TSM, SSH) not GUI (vSphere Client).
May be you ask, why should I do such a thing? well, assume you have two hosts in cluster without EVC enabled for it, in order to enable EVC for cluster, all VMs in that cluster should be powered off so the new setting would be apply to them as they coming up and if you have AD/DNS, SQL, vCenter as virtual, it means powering off these VMs as well
One way is to create secondary cluster with proper EVC config if you didn’t think about it before hand, then moving hosts to this new cluster one by one1.
Now it’s time to move most critical VMs (at least critical for making cluster working fine), for this action name of VMs, VMs ID and their storage path are needed.
For gathering these information “vim-cmd vmsvc/getallvms” command can be run, which showing all registered VMs on specific host.
Under “vim-cmd vmsvc/” there is “unregister” option; for checking it’s action and command parameters lets run this command once.
As the above picture shows, this command can be used for unregistering VMs and for this action VM IDs are needed.
From first step, I have write down two VM IDs for “SQL” and “vCenter”. (112, 48).
As the above picture shows, those two VMs are removed from first host (ESXi41-1 in my lab).
Now, list of all available VMs on the same storage which is accessible by second host (required for vMotion) is needed, for this action “ls /vmfs/volume/lun-001/” command can be use.
As long as all VMs registered with first host except “sql” and “vCenter (vc)”, I need to register them here.
After searching under “vim-cmd” commands for a while I find “registervm” command under “vim-cmd solo/“.
As the picture above shows, for registering VM to the host the full path of VM (ended with .vmx) is needed.
Also there is two other parameter which are optional, “Name” and “Resource Pool”.
“Name” would be shown up in the inventory and list of VMs and the “Resource Pool” would be the destination of specific VM, if no resource pool is selected the VMs would be place directly under the host.
So, I have tried to register these two VMs by running following commands:
vim-cmd solo/registervm /vmfs/volume/lun-001/sql/sql.vmx
vim-cmd solo/registervm /vmfs/volume/lun-001/vc/vc.vmx
After running each of these commands, System will assign new VM ID to each VM which can be used with other commands.
The last action in these series would be powering on these VMs by using “vim-cmd vmsvc/power.on VMID#” command, so the rest of configuration and then moving the other host to the cluster can be done.
But, there would be an extra step here.
As these VMs created and worked originally on other host and their UUID is registered there, so they will not power on until “system administrator” confirming the reason of new UUID.
1: For moving one host from cluster to the other, you must put that host in “Maintenance Mode” or shut it down.