Powershell to Update Vmware Tools within Windows

Script to Automatically check for Vmware Tools Update, and update if needed.

# Path to the VMware Tools executable

$vmwareToolsPath = "C:\Program Files\VMware\VMware Tools\VMwareToolboxCmd.exe"

# Function to check if VMware Tools upgrade is needed

function Check-VmwareToolsUpgradeNeeded {

    if (Test-Path $vmwareToolsPath) {

        # Check the current status of VMware Tools

        $toolsStatus = & "$vmwareToolsPath" upgrade status

        if ($toolsStatus -match "A new version of VMware Tools is available") {

            return $true

        }

        else {

            return $false

        }

    }

    else {

        return $true  # If VMware Tools is not installed, we need to install it

    }

}

# Check if an upgrade is needed

if (Check-VmwareToolsUpgradeNeeded) {

    # Define the base URL for the latest VMware Tools directory

    $baseUrl = "https://packages.vmware.com/tools/releases/latest/windows/x64/"

    # Get the HTML content of the directory page

    Write-Host "Fetching the latest VMware Tools installer URL..."

    $htmlContent = Invoke-WebRequest -Uri $baseUrl

    # Parse the HTML to find the installer file

    $installerFile = $htmlContent.Links | Where-Object { $_.href -match "VMware-tools-.*-x86_64.exe" } | Select-Object -First 1

    if ($installerFile -ne $null) {

        $installerUrl = $baseUrl + $installerFile.href

        $toolsInstallerPath = "$env:TEMP\VMware-tools-latest-x64.exe"

        # Download the installer

        Write-Host "Downloading the latest VMware Tools from $installerUrl..."

        Invoke-WebRequest -Uri $installerUrl -OutFile $toolsInstallerPath -UseBasicParsing

        # Check if the download was successful

        if (Test-Path $toolsInstallerPath) {

            Write-Host "Download successful. Installing VMware Tools..."

            # Install VMware Tools silently

            Start-Process -FilePath $toolsInstallerPath -ArgumentList "/s /v /qn REBOOT=ReallySuppress" -NoNewWindow -Wait

            Write-Host "VMware Tools installation completed."

            # Clean up the installer

            Remove-Item $toolsInstallerPath -Force

        }

        else {

            Write-Host "Failed to download VMware Tools installer."

        }

    }

    else {

        Write-Host "No installer file found at $baseUrl."

    }

}

else {

    Write-Host "VMware Tools are already up to date."

}

Authorized Reseller SecurityMetrics PCI validation certification logo