Home Lab, vSphere

Remediating VMTools using PowerCLI – Silent Install w/ No Reboot

I’m a big fan of remediating VMTools using vLCM (vSphere Lifecycle Manager), but some customers want to have the capability to script the process, not want to reboot the VM right away.

In the upcoming instructions, these are performed in my personal HomeLab. I have a handful of VMs in a CSV file I will create a variable with, take a snapshot, install VMTools silently and not reboot the VM so that it can be rebooted at a later date such as a Guest OS patch window or planned maintenance window.

Please be sure to always follow VMware By Broadcom best practices and always test in a lab environment.

The following 6 VMs saved in a CSV file on my local drive.

The following script is straightforward, it will take the VMs and create a variable, then use that variable to create your snapshots and eventually perform the Tools Update silently with no reboot.

#Creating a variable containing VM Objects from a CSV file
$VMToolsPatching = Get-Content C:\scripts\VMToolsList.csv

#Take Pre-Upgrade Snapshots
Get-VM -Name $VMToolsPatching | New-Snapshot -Name "VmTools Lifecycle" -Description "Snapshot for VMTools lifecycle" -Memory:$false -Quiesce:$false -Confirm:$false

#Perform VMTools Updates
Get-VM -Name $VMToolsPatching | Update-Tools -NoReboot

Once the snapshot and patching complete, the VM should not reboot, however the VM’s Summary page will show the Tools version is Current

On a Windows machine, if you log onto the desktop, you will find the VMTools icon indicates a small reboot icon and inform it’s pending a reboot.

There are many options for rebooting the VM once you can determine a maintenance window.

Alternate Reboot Options

While these are not the only options, nothing beats good Ol ‘fashion ‘Restart Guest OS’ via Tools, but want to share a couple of options, ultimately the solution may depend on number of VMs or fits operational procedures.

One feature in vSphere 8.0 u3 is scheduling tasks on individual VMs such as the following

If you have VCF Operations (formerly Aria & vRealize) you can use Automation Central to schedule the reboot of one or many VMs. The following is just an example of a configured Action to Reboot VMs.

Automation, Home Lab, vSphere

Creating & Remediating Image Based Clusters with VMware PowerCLI

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.