My time as a Systems Administrator came to an end 3 years ago, I had the self-realization that automation was not in my arsenal and the time needed to learn was not always there. HOWEVER..the relentless side of me still wants to learn a few new things.
While everything I did in the following blog could’ve been performed by a few single clicks within vSphere Client, performing the processes at scale or repetitive for any testing, automating makes much more sense.
The article assumes someone has some familiarity with PowerShell, PowerCLI, and VMware technologies.
To obtain the latest PowerCLI package, go to PowerShell Gallery – VMware.PowerCLI. Also, visit VMware Developer Documentation – PowerCLI
As always please take precautions and test these out always in a Test/Dev environment before executing in production environments. Also, this method is not the only way, there is always room for improvement.
This script should accomplish the following tasks:
- Create a new cluster
- Add 3 new 7.x ESXi Hosts
- Place hosts in Maintenance Mode
- Configure the cluster for Image-Based
- Add VMware Tools 12.3.5 Component to the Image Cluster
- Remediate the new cluster in Asynchronous
As a start, you may want to find out what targeted ESXi version you want to go to, any Components, or even Vendor Addons. You’re essentially querying everything available in the vLCM repository. My hosts are at 7.0u3g and after remediation should be at 7.0 U3o
The following will pull all BaseImages which are ESXi 7.x builds.
Get-LcmImage -Type BaseImage -Version '7*'

The only component we want to add/update is VMTools, the following will check for the latest version.
Get-LcmImage -Type Component *tools*

Please take the time to review the code below and replace variables and any sections with your enviornment. By no means it’s perfect but a good leap forward for me.
##The following script will create a new cluster and add 3 newly created hosts to the cluster##
##Creating a variable containing the hosts to be imported into vCenter##
$ESXiHost = Get-Content C:\scripts\<File containing hostnames>.txt
##Creates a new Cluster and adds 3 newly built hosts into vCenter##
New-Cluster -Name "<Cluster>" -Location (Get-Datacenter)
foreach ($ESXiHost in $ESXiHosts) {
Add-VMHost -Server <vCenter hostname> -Name $ESXiHost -Location "<Cluster>" -User root -Password "<password>" -Force }
Set-VMHost $ESXiHosts -State Maintenance -Confirm:$false -RunAsync | Out-Null
##The following section will go through creating variables containing the Base Image and any Components.##
##Creating a variable for base image version##
$esxiBaseImage = "7.0 U3o - 22348816"
##Creating a variable which points to the Base Image in the vLCM repository##
$esxiBaseImageName = Get-LcmImage -Type BaseImage -Version $esxiBaseImage
#For VMTools we are creating a variable containing to point to vLCM Component repository
$esxiCompToolsPackage = Get-LcmImage -Type Component -Version '*12.3.5'
#This command will begin to convert the selected cluster into an Image-Based cluster, remember **This is an Unreversable action** ##
Set-Cluster '<Cluster>' -BaseImage $esxiBaseImageName -Component $esxiCompToolsPackage -Confirm:$false
#This command will begin remediation of the cluster in asynchronous
Get-Cluster -Name '<Cluster>' | Set-Cluster -Remediate -RunAsync -AcceptEULA -Confirm:$false
The hosts in this sample were nested hosts created in the environment. Please don’t hesitate to reach out with any questions or comments.