Question

Worket to Upgrade VMware tools

  • 1 December 2022
  • 3 replies
  • 201 views

Userlevel 2
Badge

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


3 replies

Badge

Did you ever write one?

Userlevel 1
Badge +1

Im interested in this as well

 

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"
 

Reply