How to Power On Virtual Machines Using the ESXi Console

Save to My DOJO

How to Power On Virtual Machines Using the ESXi Console

Ever run into the scenario where all your VMs are down and you need to power on that one DNS server that will allow your environment to “breathe fully” again? I’ve been there. Many times. That’s why being able to power on VMs from the ESXi console can be a lifesaver. You never know when you will need it. In my experience, it’s typically due to poor planning or having to quickly move some equipment in a last minute’s notice. But it happens. Let’s go over the steps on how to get into the ESXi console and successfully power on VMs from there.

Note: Looking for more general vSphere troubleshooting help? You can find it here!

How to Open a Console Session On ESXi

There is a surprising amount of VMware admins that do not know how to open up an ESXi console from the Direct Console User Interface (DCUI) of the ESXi host. This useful tip becomes handy when your setting up ESXi at a new site and some of the networking components aren’t up yet or some issue with the ESXi NIC is occurring and you can’t get to the web UI to configure ESXi yet. Once we are either consoled in with a crash cart or connected via RMM we get to the beloved DCUI screen that everyone’s familiar with. Before we can open up a console session there is one gotcha we need to check for. Press F2 to get to the settings menu:

How to Open a Console Session On ESXi

Now select Troubleshooting Options:

Troubleshooting Options ESXi

Here’s the part that messes some people up and has personally thrown me for a loop in the past. By default, ESXi sets the Availability Timeout and Idle Timeout settings to “0”, which prevents admins from opening up a console session. So lets set this to a number higher than 0. I usually do 300. Hit Enter to save your changes:

Timeouts for ESXi Shell Access

Now, we can enable the ESXi Shell by highlighting it and pressing Enter. The display will change to “Disable ESXi Shell”, but on the right-hand side it will show that it’s now enabled:

ESXi troubleshooting Mode options

Hit ESC to get back to the main menu screen and hold ALT and press F1 to get to the console window. Now we can enter our root password and gain console access into ESXi’s console:

ESXi console

How to Power On Virtual Machines From The ESXi Console

Now that we are successfully consoled in, we can search our list of VMs with the command line. We will use the vim-cmd command, which utilizes the vSphere API to manage ESXi. We will also use the vmsvc subcommand to manipulate our VMs with the various options. Let’s get a list of all our VMs that are domain controllers so we can power them on. We will need the VMID in order to specify which VMs we want to run commands against, ESXi wants the ID number, not the name. So let’s get the VMID for our two DNS servers, the syntax is below. I’m searching for any VMs with the name “LukeLabDC” in them:

vim-cmd vmsvc/getallvms | grep LukeLabDC

The VMID is the number displayed on the first column on the left. So it’s 8 and 9. Now that we have the VMIDs let’s check each VM to see if they are on or off. The syntax looks like the below:

NOTE: you must replace “8” with whatever VMID your VM is assigned to:

vim-cmd vmsvc/power.getstate 8

Now that we know our VM(s) are powered off right now, let’s go ahead and power them on:

vim-cmd vmsvc/power.on 8

Then we’ll confirm that it’s powered on by running the same getstate subcommand again:

If we wanted to perform a graceful shutdown of the VM, then we would use power.shutdown. If we want to force the VM off, swap out the power.shutdown subcommand with power.off. Also, note that VMware tools must be installed on the VM for power.shutdown to work since it’s essentially using VMware tools to perform the graceful shutdown:

vim-cmd vmsvc/power.shutdown 8

Now, to build on this case further, what if we have an ESXi host that is completely hung? I can’t manage it through vSphere, and PowerCLI will not connect to the host either. To limit the amount of damage to the VMs, I want to shut them down before I attempt to reboot the ESXi host. A possible solution is to console into the ESXi host and get into a console session and use vim-cmd to power off each VM, similarly to what we’ve just done above.

If you have many VMs on the host, you can use a for loop to get all the VMIDs on the host and power off each one with vim-cmd. The Syntax would look like the below, just type in each line and hit enter after each one, once you type “done” the loop will run. Also, if you want to gracefully attempt to shut down each VM, use power.shutdown instead of power.off:

for i in $(vim-cmd vmsvc/getallvms |grep LukeLabDC | awk '{ print $1 }')
do
vim-cmd vmsvc/power.off $i
done

Wrap Up

Like I said earlier, you never know when you’re going to run into a scenario where you need to manage VMs through the console. I’ve been in those situations before and it’s very helpful to at least know that it’s possible to do and even more helpful to have an article bookmarked in your web browser with the steps on how to do it. Let me know in the comments below on any situations you’ve been in where you’ve had to power on VMs through the console.

Next: How to Create an ESXi Dashboard using PowerShell

[the_ad id=”4738″][thrive_leads id=’18673′]

Share this post

Not a DOJO Member yet?

Join thousands of other IT pros and receive a weekly roundup email with the latest content & updates!

1 thoughts on "How to Power On Virtual Machines Using the ESXi Console"

Leave a comment

Your email address will not be published. Required fields are marked *