Automated VMware Tools upgrades using your VC and Perl

I was upgrading a VI 2.0.2/3.0.2 system to VI 2.5/3.5 and found that upgrading VMware Tools was becoming a real pain. So I decided to look for a better way. I first did the usual search hoping to find a quickie but no luck. I searched the VMware forums to find that everyone was using the MSI package in a manner external to the VI system. This did not address any Linux or Unix systems so here is what I came up with to address the lack of automation.

First I installed the VMware VI perl Tool Kit on the VC.

I changed the NTFS rights to the Tool Kit directory to an dedicated admin user ID and SYSTEM only, I then populated the visdk.rc config file in the same directory with the following parms


I also added the following ENV variable to the SYSTEM Context.

System variable ss

I wrote a short simple Perl script to make use of the power of the VC and have it take care of the task using it’s own built capability. Frankly I just don’t see why VMware did not have a scheduled task item to handle this job in the VC.  

#!/usr/bin/perl -w
# Requires a text file named VMToolsUpgradeList.txt
# containing VM names which the last of must not end with a CR
# Author: Mike La Spina
#   Date: May 24, 2008
# –host TheVC

use strict;
use warnings;
use VMware::VIRuntime;

my %opts = (
   ‘host’ => {
      type => “=s”,
      help => “Host is the VIM API service target”,
      required => 0,

my ($property_name, $property_value);
   $property_name = “”;
   $property_value = ”;

# get all VMs with out of date tools
my $vm_views = Vim::find_entity_views(view_type => ‘VirtualMachine’,
                  filter => { ‘guest.toolsStatus’ => ‘toolsOld’ });

foreach (@$vm_views) {
      my $nameVM = $_->name;
      #print $nameVM . “n”;
      open FILE, “<”, “VMToolsUpgradeList.txt” or die $!;
      my @lines = <FILE>;
      foreach my $vmname (@lines) {
         if ($nameVM eq $vmname) {
            print “Issued VMware Tools upgrade task on ” . $nameVM . “n”;
   next ;
print “Tools Upgrade scan completedn”;

The script requires a text file which I populated all of the VM names that I wanted to upgrade VMware Tools on. It’s noted in the script.

I created a windows task to run the perl script at 3:30AM and set it up to login in with the dedicated adminID and password.

I can now add any VM names to the VMToolsUpgradeList.txt and schedule the event to run after hours.

There are no issues with MSI deployements or Linux installs etc.

Till next time…

Tags: , , , ,

Site Contents: © 2008  Mike La Spina


  • Mark says:

    Genius. Exactly what I wanted :)

  • Ronald says:

    Hi Mike,

    Exactly the way to go. Unfort, I get a lot of errors and I am not used to Perl.
    This is what I get :
    Bareword found where operator expected at C:Program FilesVMwareVMware VI Perl line 40, near “print “Tools”
    (Might be a runaway multi-line “” string starting on line 27)
    (Do you need to predeclare print?)
    Global symbol “$vm_views” requires explicit package name at C:Program FilesVMw
    areVMware VI Perl line 27.
    Global symbol “$vm_views” requires explicit package name at C:Program FilesVMw
    areVMware VI Perl line 27.
    Global symbol “$nameVM” requires explicit package name at C:Program FilesVMwar
    eVMware VI Perl line 27.
    Global symbol “$nameVM” requires explicit package name at C:Program FilesVMwar
    eVMware VI Perl line 27.
    syntax error at C:Program FilesVMwareVMware VI Perl ToolkitPerlbinupgradet line 40, near “print “Tools Upgrade ”
    Can’t find string terminator ‘”‘ anywhere before EOF at C:Program FilesVMware
    VMware VI Perl line 40.

    Can you shine a light ?

    Thanks ! Plz use my email mentioned.

  • Ronald says:


    Sorry for my previous post, solved that already. Plz delete =)
    However, the test if ($nameVM eq $vmname) is always false. I printed out both to screen, they look exactly the same. Still, it does not step into the statement. Any idea what can be wrong ?


  • Ronald says:

    Hi Mike (last post),

    Got it to work ! Thanks for sharing. The test with the $vmname and $namevm was also false, because the text file has some trailing garbage (even if it’s truncated in Notepad). I added a trim funtion to the script and now I am checking against the trimmed variables and it started to work.

    Thanks again !



Leave a Reply

XHTML: You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>