I received a question this week from a reader who was looking to change the VMware Tools upgrade policy for a few hundred virtual machines and wanted to know if it was possible to automate this. The answer is absolutely yes!
By default the VMware Tools upgrade policy is disabled and set to "manual" mode. If you want the vSphere platform to automatically check and upgrade VMware Tools upon a system power cycle, then you can enable it by going to Edit VM->Options->Tools->Check and upgrade Tools during power cycling.
To update this configuration, there is a property in the vSphere API called toolsUpgradePolicy which can accept two values: manual or upgradeAtPowerCycle.
Here is a vSphere SDK for Perl script updateVMToolsPolicy.pl that supports two types of operations: "list" and "update". The list operation will show you all VMs and their currently configured upgrade policy, by default they should be all manual unless you have changed it manually. The update operation will allow you to configure a list of VMs and policy you designate. This change can be done while the VM is running, you do not need to make any changes to the guestOS that is running.
Here is an example of the "list" operation:
If you want to take all the VMs that have "manual" policy and change them over to "upgradeAtPowerCycle", you can copy the output to a file and then use a find or UNIX/Linux grep command to search for entries that have the word "manual".
Here is the command you can use if you are on a UNIX/Linux system:
cat output | grep "manual" | awk -F '["|"]' '{print $2}'
Here is the command to get the first column which contains the VM display name:
cat output | grep "manual" | awk -F '["|"]' '{print $2}' > VMLIST
Lastly, you just need to take the previous command and redirect that to a file which will then be used in the "update" operation. You can also take the output and using an editor to get to the final output, use whatever you are comfortable with.
Here is an example of the commands listed above:
Now that we have the list of VMs we are interested in updating, we just need to select the policy and perform the "update" command. Here is an example:
So there you have it, you can now easily automate the the VMware Tools upgrade policy for any or all your VMs without having to edit each one manually.
Chopper3 says
You William, are a star, thank you very much indeed.
William says
@Chopper3,
np, glad I could help
John Walsh says
Another awesome post and script. Many thanks!
William says
@John,
np! and thanks for the comment
DeanH says
This comment has been removed by the author.
DeanH says
Here is the PowerCLI version to set VMTools to "UpgradeAtPowerCycle":
$vms = Get-VM | where {(Get-Cluster).Name -eq "CLUSTER NAME"}
Foreach ($vm in $vms) {
$config = New-Object VMware.Vim.VirtualMachineConfigSpec
$config.Tools = New-Object VMware.Vim.ToolsConfigInfo
$config.Tools.ToolsUpgradePolicy = "UpgradeAtPowerCycle"
$vm.ExtensionData.ReconfigVM($config)
}
Cheers
Anonymous says
Shouldn't the last line be this:
$vm.ReconfigVM($config)
UKMAK says
Check and upgrade Tools during power cycling feature does not work in ESXi 5.0
In ESX/ESXi 4.1, the Check and upgrade Tools during power cycling option was available to upgrade VMware Tools when the virtual machine shut down. This feature does not work in ESXi 5. Ignore any documentation procedures related to this feature.
Workaround: Install VMware Tools manually.
https://www.vmware.com/support/vsphere5/doc/vsphere-esx-vcenter-server-50-release-notes.html#vmissues
Anonymous says
Is there a way to automate Install VM Tools completely without human interaction by calling perl or java API? Now I am trying to do this but it seems the VM tools installer started but always popup a window to require clicking the "Next" button.
William says
Yes, there is a vSphere API to automate the installation of VMware Tools. The method you're looking for is UpgradeTools_Task() http://pubs.vmware.com/vsphere-51/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvim.VirtualMachine.html and this is the same operation if you were to right click and say Install/Upgrade VMware Tools and clicking next.
Anonymous says
William, thanks for your reply.
In http://pubs.vmware.com/vsphere-51/topic/com.vmware.ICbase/PDF/wssdk_prog_guide_5_1.pdf Page 130,
UpgradeToolsTask – Performs an UPGRADE of VMware Tools. This method assumes VMware Tools has been installed and is running.
What I need to do is automating INSTALL VM TOOLS. In order to install VM tools, I need to call the MountToolsInstaller( in Java) which does automatically start to run the VM tools installation program in the VM but this installation wizard pops up a window that requires human being click "Next" button in the VM otherwise the installation wizard just stays there forever.
My question for you is: how can I fully automate the INSTALL VM tools operation without any human being interaction? or is it possible to do this? The ideal result would be the VM tools installed automatically in VM instead of requiring human being click the Next button in the VM.
William says
If you call the MountToolsInstaller(), you can also pass in parameters for an unattended installation, you'll have to look up the options. I recommend you do this manually via CLI and then once you have all the flags, then you can pass that into your script which will perform the installation.
Take a look at this VMware KB which includes some silent install flags which may help http://kb.vmware.com/kb/1018377
Anonymous says
Thanks, William.
The problem here is: in java MountToolsInstaller( ManagedObjectReference) only takes one parameter, the ManagedObjectReference of VM. There is no way to pass the option string into the MountToolsInstaller() in the java program.
Nitin says
Hi,
Were you able to install vmware tools automatically without any human being interaction.
Can you please share steps to do so.
Regards,
Nitin
William says
I'm sorry, you're right, that's only valid for Upgrade method. The best method that I can see is basically mount up the ISO and then using the Guest Operations to perform the unattended installation (as you would from guestOS but using the CLI)
lazyvm says
Thanks for the post William. I have a question
I am seeing problem setting ¨upgradeAtPowerCycle¨ especially on database servers . A server reboot is happening right after the vmtools update and this is causing issue on SQL servers.My advice not to set this option on all VMs. Let me know if you got any other thoughts