Automatically upgrade VMWare Tools on multiple Virtual Machines

A new version of ESX often comes with a new version of VMWare Tools. In my case, I did a migration of ESX 3.5 to vSphere (4.0). A manual installation of VMWare Tools would be pretty time-wasting (50 virtual machines). Therefore, I’ve searched on Google, and found the following solution: Powershell!

With a Powershell command, you can set all virtual machines to install or upgrade VMWare Tools at the next power-on.

Requirements:

To set all virtual machines to automatically upgrade VMWare Tools at the next power-on, do the following:

  1. Start the VI Toolkit (the link can be found in your start menu after installation of the VI Toolkit
  2. Connect to the Virtual Center server with the command:
    connect-viserver -server <VirtualCenter Server IP address> -user <VirtualCenter User> -password <VirtualCenter password>
  3. Copy the following command to your VI Toolkit Window:
    Foreach ($v in (get-vm)) {
    $vm = $v | Get-View
    $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
    $vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
    $vm.ReconfigVM($vmConfigSpec)
    }

You may have to press ENTER twice, before it executes the command. Execution of the command may take some time. You can view progress in the Recent Tasks section in the vSphere client. All your servers will be configured one by one.

After execution, all your VM’s are configured to update with the next power-on. You can verify this by doing this:
Right-click a VM in your vSphere client > click Edit Settings > click Tab Options (second tab) > click VMWare Tools.
You should see the option “Check and upgrade tools before each power-on” checked.

vsphere_check_and_upgrade_vmware_tools

To undo all this, run the same command, but instead of “UpgradeAtPowerCycle“, set “Manual“. This results in the following command:
Foreach ($v in (get-vm)) {
$vm = $v | Get-View }
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “Manual”
$vm.ReconfigVM($vmConfigSpec)
}

You may want only particular servers to upgrade (or not upgrade) the VMWare Tools. In that case, you can use the IF-command in Powershell. For example, if you have 10 servers starting with the name “Citrix” (like Citrix1, Citrix2, etc.), you run the following command:
Foreach ($v in (get-vm)) {
If ( $v -like “Citrix*”) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “manual”
$vm.ReconfigVM($vmConfigSpec)
}
}

In this command, the asterisk * functions as a wildcard.

Another example, if you want to set all virtual machines, except Citrix, to install the VMWare Tools, you run the following command:
Foreach ($v in (get-vm)) {
If ( $v -notlike “Citrix*”) {
$vm = $v | Get-View
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$vmConfigSpec.Tools = New-Object VMware.Vim.ToolsConfigInfo
$vmConfigSpec.Tools.ToolsUpgradePolicy = “UpgradeAtPowerCycle”
$vm.ReconfigVM($vmConfigSpec)
}
}

NOTE: do not forget to always first connect to the Virtual Center server with the connect-viserver cmdlet. Otherwise, it will not work :)

Leave a Reply

7 Comments on "Automatically upgrade VMWare Tools on multiple Virtual Machines"

Notify of
avatar
Sort by:   newest | oldest | most voted
Geoffrey Stenta
Guest

I tested this out and it appears to have set the option correctly to upgrade at next power cycle.

I did receive this error message, and am not sure if there is a workaround at this time.

Exception calling “ReconfigVM” with “1” argument(s): “The method is disabled by
‘VMWARE.SIM'”
At line:6 char:15
+ $vm.ReconfigVM <<<< ($vmConfigSpec)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException

JD
Guest

Are you possibly trying to set the option on View VMs?

supermancsm
Guest

vSphere Center 4.1 already has this feature availble

John Qvortrup
Guest

Thanks mate you saved my day.

Garp1997
Guest

Hi,
is it possible to pass a list of VMs to shutdown and to change the settings? Many thanks in advance.

Chris
Guest

The first script (set all VMs with this attribute) stops if any given VM has a failure.

Sealey Tools
Guest

What is the difference between Page File and Virtual Memory?

wpDiscuz