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)

6 thoughts on “Upgrading VMware Tools in Batch using PowerCLI

  1. Thanks for posting, I will have to give it a try. One thing to mention is that the commented out header of your script talks about upgrading virtual machine hardware and making sure the VMs are powered off…

    1. Hi Kevin,

      Yes apologies for that, i have been working on a Hardware upgrade script as well. I must of copied the comments over from the script. I have now updated this.

      thanks

  2. what’s the format of the CSV file? dose the collum with the VM names just need the word ‘name’ at the top of the column.

    Also

    If your using vCloud director for many of the VM’s is this still the recommended method or should I be hitting vCD?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s