Recently I was presented with the need to change the time synchronization and VM Tools installation options for a number of VM guest machines.

While this is not challenging to do through the UI, I’m a big fan of doing everything possible through PowerCLI. And if you have larger numbers of machines in your VMware environment, those few clicks seem to get exponentially more difficult. Besides the convenience in greater numbers, it’s just good to become more familiar with PowerCLI wherevery possible.

Here is what we are looking at as the “before” view:

Even more exciting for my particular configuration is that I’ve got two vCenter servers running in Linked Mode. So this will add one requirement to the script to be able to connect to multiple instances of vCenter to enumerate the VM guests.

I am assuming that you are running your PowerCLI console with administrative privileges, otherwise you will be prompted for your credentials upon connecting to the VI servers.

If you only have one vCenter server, you can simply make the $VIServers = “yourservername” without a second server listed. Conversely, you may have more than two vCenter instances to speak to, or you may be connecting directly to the vSphere hosts. In those cases you may add additional server names in a comma separated list where the servername is enclosed in double quotes.

Here is the script:

# Connect to your VI Server(s)
#
# Fill in the VI Server(s) using “servername”,”servername” depending on how many you wish to attach to
$VIServers = “vCenterServer1″,”vCenterServer2”

Once we have run the script, you will see activity in two places. Firstly you will see in your PowerCLI console that there are vCenter tasks being created and started:

Next you will be able to view inside your VMware vCenter client that a Reconfigure Virtual Machine task is submitted and after a very short time will show as completed.

Now that the process has completed, you may now check the VM settings in your VI Client and as if by magic, the checkboxes are both set!

It’s just that easy! In fact, this does not need to be a global change. I’ve only made it that way because of my specific situation. If you modify the $VMGuest = Get-VMto add parameters you could narrow the focus to some specific targets. In fact you will want to do this to test out most likely.

Here is a simple way to apply the changes to all servers whose name begins with WINSRV using the -Name parameter.

$VMGuest = Get-VM -Name WINSRV*

Also, if you want to make the change in the other direction to modify the VM Tools options to be unchecked, this is the line that you would use within the ForEach loop:

$spec.tools.toolsUpgradePolicy = “manual”

And for setting the Time Synchronization option to be unchecked, this is the line you would use:

This is a great script that saved me some dev time. Just what I needed as we are going to change all of our servers over to a different time sync setup.

Just a side note of one little glitch I ran into (maybe it’s my env). I had to change from double quotes around the vCenter server names to single quotes – then it was happy! Still an awesome job though!

Hi Eric,
I would like to propose a little modification to your script. Here is what happened to me: on a vCenter with a few thousands VMs I found duplicate VM IDs, which ran the script into trouble. I was surprised to see that, even if I specified clearly a set of VMs, other VMs were targeted too. So I changed the line
$MyVM = Get-View -Id $VMGuest.Id
into
$MyVM = $VM | Get-View
This way I eliminated the confusion.