ITExperience.NET Rotating Header Image

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 :)

3 Comments

  1. Garp1997 says:

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

    (Quote)

  2. Chris says:

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

    (Quote)

  3. Sealey Tools says:

    What is the difference between Page File and Virtual Memory?  

    (Quote)

Leave a Reply

Comments without hyperlinks are immediately visible. However, if you post a comment that includes a hyperlink, your comment requires approval. This can take up to one day.