Managing VMware Tools with PowerCLI

All virtualization platforms have some type of client package of tools that is used for communications between the virtual machine and the hypervisor or otherwise managing the virtual machine guest. Often if the version of client tools is behind what the server is expecting, you lose some ability to manage the virtual machine guest. VMware is no different. However, with PowerShell and the PowerCLI snapin, it is pretty easy to update all of your clients to the most recent version of client tools. Today I’ll show you how to manage VMware tools using PowerCLI – specifically, updating and installing the tools.

Finding the Current Version

The version information is part of the virtual machine object, but it is a little tricky to get to. Let me walk you through it. First, we’ll look at a single virtual machine.

​ PS C:\> $vm = get-vm MyCompanyDC

The virtual machine has a property called ExtensionData. This object is a complex object which contains another object as a property called Guest. Using Select-Object with the ExpandProperty parameter, we can view the current tools status.

​ PS C:\> $vm | select -expandproperty ExtensionData | select -expandproperty guest

As you can see in Figure 1, tools are outdated on this virtual machine.
Managing VMware Tools with PowerCLI

Here’s a shortcut way to get the same information.

​ PS C:\> $vm.ExtensionData.Guest | Select Hostname,Tools*
HostName            : MYCOMPANY-DC01.MYCOMPANY.LOCAL
ToolsStatus         : toolsOld
ToolsVersionStatus  : guestToolsNeedUpgrade
ToolsVersionStatus2 : guestToolsSupportedOld
ToolsRunningStatus  : guestToolsRunning

But this only works for a single VM. For checking multiple virtual machines you can try a command like this:

​ PS C:\> get-vm globomantics*,*DC | Select Name,@{Name="ToolsVersion";Expression={$_.ExtensionData.Guest.ToolsVersion}},@{Name="ToolsStatus";Expression={$_.ExtensionData.Guest.ToolsVersionStatus}}

Using Select-Object with custom hash tables I created some new properties to display tool information.
Managing VMware Tools with PowerCLI select-object
As you can see in Figure 2, of the virtual machines I am concerned about, MyCompanyDC needs an upgrade.

Updating VMware Tools with PowerCLI

To update VMware tools, the virtual machine needs to be running. Now, you could manually connect to the virtual machine and upgrade the tools, but that isn’t practical if you have multiple machines to upgrade. To update tools, there must be an older version already installed. Here’s how easy it is to update.

​ PS C:\> get-vm mycompanydc | Update-Tools

Managing VMware Tools with PowerCLI update tools
As you can see in Figure 3 there is a progress bar. Because this might take a little bit to complete, you might want to run Update-Tools with the –RunAsync parameter, which will create a VMware update tools background task. Also be aware that the virtual machine will reboot upon completion unless you include the –NoReboot parameter. After a few minutes, my virtual machine is up to date in Figure 4.
Managing VMware Tools with PowerCLI update
Even though I only updated a single machine, you should be able to update as many virtual machines as you get with Get-VM.

Installing VMware Tools

If you have a new virtual machine, you will need to manually install VMware tools. As with upgrading, the virtual machine must be running. Unfortunately, I cannot find any easy way to accomplish this from the desktop. It is sort of a catch-22: You can’t install the tools because the tools aren’t installed. If you don’t want to have to deal with the virtual machine console, I can get you part of the way from the command line.
My virtual machine, Petri-1, is a fresh Windows Server 2012 system running server core. What I can do is mount the VMware Tools ISO from my desktop on the virtual machine.

​ PS C:\> get-vm petri-1 | Mount-Tools

At this point I need to logon to the virtual machine, open a command prompt, and run:

​ C:\> D:\Setup /s /v /qn

This will do a silent installation of the VMware Tools followed by an automatic reboot. Manually installing like this works fine if all you have is a remote desktop connection. But if the guest has PowerShell installed with remoting enabled, you should be able to achieve the same result using Invoke-Command:

​ PS C:\> Invoke-Command –scriptblock {D:\Setup /s /v /qn} –computer petri-1

When you are finished, you can dismount the tools ISO.

​ PS C:\> get-vm petri-1 | Dismount-Tools

Unfortunately, none of this is going to be useful on a virgin virtual machine. If you have to manually install VMware Tools, you might as well use the menu option from the virtual machine console.
 
The techniques I’ve shown here assume you have a Windows-based operating system on your guests. You will want to keep all of your virtual machines updated, and with PowerShell that doesn’t take much effort at all.