Skip to content

Upgrading VMware Tools in Batch using PowerCLI

Technical Article

PowerCLI script that reads a CSV of virtual machine names and runs Update-Tools with NoReboot against a target vCenter cluster, then emails a report of upgraded VMs once the batch VMware Tools update is complete.

Categories
VirtualisationVmware
Tags
PowercliUpgrade Vmware ToolsVirtual EnvironmentVmware Tools
Upgrading VMware Tools in Batch using PowerCLI

I have written a PowerCLI script that simplifies the process when upgrading VMware tools on all Servers in a Virtual Environment after a VMware version / patching version update.

Whist running the script, you will need to fill in the blanks with regards to vCenter name, Cluster name, and Email details.

Ensure you have the required version of PowerCLI installed before attempting to run this script.

# Upgrade of VMTools
# Notes: Script to update VMtools by batch using a CSV file
# By Ryan Mangan 03/06/2014
#
# Connect to vcenter server
Write-Host "******  VMware Tools Upgrade Script ******" -ForegroundColor Green
Add-PSSnapin VMware.VimAutomation.Core
$vcenter = Read-Host "Enter the vCenter Instance"
Connect-VIServer -Server $vcenter -WarningAction SilentlyContinue
# Import vm name from csv file

$CSVLoc = Read-Host "enter CSV File location e.g c:\temp\deploy.csv"
Import-Csv $CSVLoc |
foreach {
    $strNewVMName = $_.name

    # Update VMtools without reboot
    $Clustername = Read-Host "enter cluster name"
    Get-Cluster $Clustername | Get-VM $strNewVMName | Update-Tools -NoReboot
    Write-Host "Updated $strNewVMName ------ "

    $report += $strNewVMName
}
Write-Host "Sleeping ..."
Sleep 120
# Send out an email with the names
$SenderID = Read-Host "enter email from address"
$RecipEmailID = Read-Host "enter repcipient email id"
$EMAILSRV = Read-Host "enter Email Server Name"
$emailFrom = $SenderID
$emailTo = $RecipEmailID
$subject = "VMware Tools Updated"
$smtpServer = $EMAILSRV
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $Report)