Wednesday 20 March 2013

How to Power Off Virtual Machine from CLI in different versions of ESX/ESXi server

Using the ESXi 5.x esxcli command to power off a virtual machine

Step 1: Find the ESXi server on which the virtual machine is running
Step 2: Ensure remote tech support mode is enabled.
Step 3: Enable ssh service to access command line interface

Click on ESXi server --> Got to configuration tab--> click on security profile under software section --> click on properties of services section --> select ssh --> click on options and start the service

Step 4: Login to the ESXi server using putty. Provide username and password when prompted.
Step 5: Execute the below command to see the list of vms running under this ESXi server

#esxcli vm process list

Note: World ID, UUID, Display Name, and path to the .vmx configuration file will be displayed.

Step 6: Power Off the virtual machine that u want using the below command

#excli vm process kill --type=[soft,hard,force] --world-id=WorldNumber
notes: Three power-off methods are available. Soft is the most graceful, hard performs an immediate shutdown, and force should be used as a last resort.
Alternate power off command syntax is: esxcli vm process kill -t [soft,hard,force] -w WorldNumber
Step 7: Repeat Step 5 and validate that the virtual machine is no longer running.

Using the ESXi 4.x esxcli command to power off a virtual machine

Perform step 1 - step 4 from above procedure

Step 5: Get a list of running virtual machines, identified by World ID, UUID, Display Name, and path to the .vmx configuration file, using this command:

#esxcli vms vm list

Step 6: Power off one of the virtual machines from the list using this command:

#esxcli vms vm kill --type=[soft,hard,force] --world-id=WorldNumber

Using the ESXi command-line utility vim-cmd to power off the virtual machine

Step 1: On the ESXi console, enter Tech Support mode and log in as root. For more information, see Tech Support Mode for Emergency Support (1003677).

Step 2: Get a list of all registered virtual machines, identified by their VMID, Display Name, and path to the .vmx configuration file, using this command:

#vim-cmd vmsvc/getallvms
To get the current state of a virtual machine:

#vim-cmd vmsvc/power.getstate VMID

Step 3: Shutdown the virtual machine using the VMID found in Step 2 and run:

#vim-cmd vmsvc/power.shutdown VMID

Note: If the virtual machine fails to shut down, use this command:

#vim-cmd vmsvc/power.off VMID

 

No comments:

Post a Comment