Upgrading ESXi 6.0 hosts with PowerCLI

The last step in my migration project was to actually upgrade the hosts to a supported version. This means that all hosts are upgraded to 6.7 except for those hosts that are a bit to old and only support 6.5.

For the upgrade, I used Update Manager to store the ESXi 6.7 ISO file and to attach the upgrade baseline to the clusters that can run 6.7. Unfortunately, the VIB from the Cisco 1000V Distributed Switch was still installed but not compatible with the upgrade image. So I needed to come up with a solution to remove that VIB before upgrading the host. I wrote the following script to perform these steps:

First, the script performs the following steps:

  • Get a reference to the cluster
  • Disable HA
  • Disconnect ISO’s from VMs and set the CD to disconnected
  • Attach the upgrade baseline and the patch baseline to the cluster
  • Test compliance of the upgrade baseline
  • Get a reference to all hosts that are not compliant

Then the script performs the following steps to every host that is not compliant:

  • Enter Maintenance Mode
  • Remove the VIB
  • Upgrade the host
  • Test compliance of the patch baseline
  • Patch the host
  • Exit Maintenance Mode

On average, every host took about 75 minutes to do the upgrade and to install the patches. But because it is automated it took me less than 5 minutes per cluster.

Unfortunately, this script could only perform an upgrade to 6.7 as this is the only version you can import in Update Manager. So I needed another script for upgrading hosts to 6.5.

This script uses a local upgrade method where the upgrade ZIP file is available on a datastore. First, the script performs the following steps:

  • Get a reference to the cluster
  • Select a datastore in each datacenter with the most available free space
  • Copy the offline ZIP file to both datastores
  • Disconnect ISO’s from VMs and set the CD to disconnected

Then the script performs the following steps to every host in the cluster:

  • Enter Maintenance Mode
  • Remove the VIB
  • Upgrade the host
  • Exit Maintenance Mode

When every host is upgraded the offline ZIP files are removed from the datastores. And with that, all hosts in the cluster are upgraded to 6.5. The only remaining task was to patch the hosts, but for this, I could use the Update Manager again.