It is possible to use a GUI to start up and shut down VMware vSphere clusters, but as we all know, using a GUI does not usually scale well. PowerCLI combined with a bit of PowerShell is a much better way to manage the startup and shutdown of vSphere as I will show in this article.

Unfortunately, there may be instances where it is necessary to shut down and or start up entire vSphere clusters. An example would be if there is a power outage in a datacenter and there is no generator, or if a generator malfunctions. For this reason, it is a good idea to understand not only the proper sequence for these processes, but also the most efficient one.

Since vCenter is the heart of a vSphere cluster, it is probably the most important aspect of these processes. It is important to understand that not properly dealing with vCenter during a shutdown or startup can cause many issues with VMs and hosts.

This article assumes a very simple vSphere setup, with multiple hosts: one vCenter (with local database) that is a VM in the cluster, and only one cluster. It also assumes all VMs have VMtools running, which is necessary for shutdown with PowerCLI.

Shutting down a vSphere cluster ^

The process of shutting down a cluster is as follows:

  1. Shut down all virtual machines (VMs) except for the vCenter VM.
  2. Place the hosts in maintenance mode.
  3. Shut down the vCenter virtual machine.
  4. Shut down each ESXi host.

The first task we will do is connect to vCenter in PowerCLI:

C:\> Connect-ViServer vcenter

Now we will shut down all VMs except for vCenter by filtering it out with the Where-Object cmdlet. Here I pipe the result of Get-VM to Stop-VMGuest, which will grab all VMs in the cluster and start gracefully shutting them down.

C:\> Get-VM | Where-object {$ -notlike 'vcenter' }  | Stop-VMGuest -Confirm:$false

I can see the status of VMs by using Get-VM again:

C:\> Get-VM

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
vcenter              PoweredOn  2        8.000

Once all VMs are off, I want to grab all the hostnames of my ESXi hosts  to shut them down in a later step and also place them into maintenance mode:

VMHosts into maintenance mode

VMHosts into maintenance mode

 Now, I shut down the vCenter VM:

C:\> Stop-VMGuest –Name vcenter

Finally, I shut down all ESXi hosts by connecting to them directly with Connect-VIServer and using the Stop-VMHost cmdlet.

C:\> Connect-VIServer -Server $VMhosts -Credential (Get-Credential)
C:\> $VMhosts | ForEach-Object {Stop-VMHost -VMHost $_ -Server $_ -RunAsync}

At this point, my entire vSphere cluster is down.

Starting up a vSphere cluster ^

Since we are starting the entire vSphere cluster up, the first thing we need to do is to ensure the storage our cluster uses is operational, since usually VMs are typically located there. Then, we follow this outline:

  1. Power on all VMHosts via Intelligent Platform Interface (IPMI).
  2. Find and start the vCenter virtual machine.
  3. Connect to vCenter and start all VMs in the cluster.

I prefer to use IPMI to power on physical servers as it allows me to do this very quickly and easily. Many people do not know this, but you can do it natively with PowerShell as I illustrated in my previous 4sysops article here. Obviously, you must set up your ESXi hosts to work via IPMI for this to work correctly.

To boot the ESXi hosts, I can run one command using the Get-Credential cmdlet for your IPMI username and password. Notice I add "-ipmi" in the target address since the IPMI address is usually a separate NIC on the host:

C:\> $VMHosts | Start-PcsvDevice -TargetAddress ($_ + ‘-ipmi’) -Credential (Get-Credential) -ManagementProtocol IPMI

Now that our ESXi hosts are booted and online, we can find the vCenter VM and boot it. To do this, I use a function I keep in Github called Get-vCenterESXiHost. This function connects to each VMhost and uses Get-VM to see whether the vCenter VM is on that host.

C:\> Get-VCenterEsxiHost -VCenterVMName 'vcenter' -ESXiHosts $VMHosts -RootCredential (Get-Credential)
C:\> Start-VM –VM vcenter –Server VMHost1

Once vCenter is up and running, we can connect to it and start all VMs in the cluster:

Subscribe to 4sysops newsletter!

C:\> Connect-ViServer vcenter
C:\> Start-VM –VM (Get-VM)
1 Comment

Leave a reply

Your email address will not be published.


© 4sysops 2006 - 2022


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account