Wednesday, March 4, 2020

Executing virtual machine related-operations via the ESXi Shell

 Consider a situation that you don't have access to any type of vSphere client (and also web client). What should we do for managing virtual infrastructure objects and components? especially management operations for virtual machines is a some kind of regular procedure that you may need to run immediately. So there is many CLI for such as this situation that I want to review in this post.

 To check all of running VMs in host-level:
esxcli vm process list

 Also you can stop them via running kill syntax with the related world-ID:
esxcli vm process -w 12345 -t soft


(You can try each one of soft, hard & force with -t based on VM status)

But there is nothing to made power-on a VM with esxcli, so we can go for the next CLI: vim-cmd
 vim-cmd vmsvc/power.on /vmfs/volumes/{datastore-name}/{vm-directory}/vm.vmx

You can execute many other virtual machine operations like power.off, shutdown, reset, reboot and so on.
 If you want to check all running VMs via the vim-cmd you can run the following command too:
vim-cmd vmsvc/getallvms

 If you want to check the status of a VM with more details you can use the get.summary. Look at the results of following command:
vim-cmd vmsvc/get.summary 5 (vmid) | grep State


 And also with get.runtime to recieve many detail information about that VM like the boot time:
vim-cmd vmsvc/get.runtime 5 | grep boot


 


And for gathering more information about the guest OS like the VMkernel port IP Address, Subnet mask, MAC address and ESXi configured FQDN:
 



For register/unregister a VM you can run the following operations:
vim-cmd solo/register ....
vim-cmd vmsvc/unregister ...









 Attention: There is many dangerous operations like destroy or device.diskremove so be careful of using each of them.

In another post I will review about the vim-cmd hostsvc command-line
I hope it has been useful for you all guys ;)
 
   

No comments:

Post a Comment

I will start a new journey soon ...