Question

Worket to Upgrade VMware tools

  • 1 December 2022
  • 4 replies
  • 237 views

Userlevel 2
Badge

Just checking if somebody here in the community created a worklet that upgrades vmware tools and works?


4 replies

Badge

Did you ever write one?

Userlevel 1
Badge +1

Im interested in this as well

 

Userlevel 1
Badge

How about this.

 

# Function to update VMware Tools on a virtual machine
function Update-VMwareTools {
    param(
        [string]$VMName,
        [string]$vCenterServer,
        [string]$Username,
        [string]$Password
    )

    # Connect to the vCenter server
    Connect-VIServer -Server $vCenterServer -User $Username -Password $Password

    # Get the virtual machine object
    $VM = Get-VM -Name $VMName

    if ($VM) {
        # Check if VMware Tools is out of date
        if ($VM.ExtensionData.Guest.ToolsVersionStatus -eq "toolsOld") {
            # Update VMware Tools
            $Task = $VM | Update-Tools -NoReboot -RunAsync

            # Wait for the task to complete
            $Task | Wait-Task

            Write-Host "VMware Tools updated on $VMName"
        } else {
            Write-Host "VMware Tools on $VMName is already up to date"
        }
    } else {
        Write-Host "Virtual machine $VMName not found"
    }

    # Disconnect from the vCenter server
    Disconnect-VIServer -Server $vCenterServer -Confirm:$false
}

# Usage example
Update-VMwareTools -VMName "YourVMName" -vCenterServer "YourVCenterServer" -Username "YourUsername" -Password "YourPassword"
 

Userlevel 3
Badge

Hi Afonso,

I have been upgrading VMware tools like this:

This is just a Required Software policy since I find the Scope to be easier to use than the Evaluation code in a worklet. If a new Vmware tools version comes out, its easy enough to replace the installation file (from vmware) and increment the package version.

 

There is a way to trigger the update from within the host, but it depends on some Vsphere settings being in place to allow for it:

& "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe" upgrade status
& "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe" upgrade start

The ‘upgrade start’ command will not return anything into the Activity Log if its already at the latest version.

Reply