DiscoPosse – Using the chicken to measure IT
Technology, Cycling, Music and Madness


Technology

July 24, 2012

PowerCLI – Globally setting VM Tools time sync and version upgrade options

More articles by »
Written by: Eric
Tags: , , , , , ,

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″

# Connect to the VI servers to enumerate the resources
ForEach ($VIServer in $VIServers) {
      Connect-VIServer $VIServer
}

# Query for the VM guests
$VMGuests = Get-VM

# Loop through your VM guests, set the VM Tools upgrade checkbox and the Sync Time checkbox to true
ForEach ($VMGuest in $VMGuests) {
      $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
      $spec.changeVersion = $VMGuest.ExtensionData.Config.ChangeVersion
      $spec.tools = New-Object VMWare.Vim.ToolsConfigInfo
      $spec.tools.toolsUpgradePolicy = “upgradeAtPowerCycle”
      $spec.tools.syncTimeWithHost = $true

      # Apply the changes
      $MyVM = Get-View -Id $VMGuest.Id
      $MyVM.ReconfigVM_Task($spec)
}

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-VM to 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:

$spec.syncTimeWithHost = $false

And that wraps it up. Enjoy!



About the Author

Eric





 
 

 
vexpert_logo_q109

vExpert 2013 – Look who just joined the club!!

I have one word to describe the feeling right now: Wow! I am humbled and thankful to VMware, John Troyer, Angelo Luciani and the whole community who have kindly added me to the vExpert list for 2013. This is truly an honour for...
by Eric
0

 
 
tovmug

Toronto VMUG: May 23rd, 2013 Event Recap and Private Cloud Presentation

It was a beautiful sunny morning in Toronto and a great day for a VMUG meeting! May 23rd brought the first VMUG meeting of the spring here and the audience showed that they were ready to show some community love today. There we...
by Eric
0

 
 
newfeature

VMware Hybrid Cloud Launch Day – Why this is important, and What is New

So today is a big announcement day for VMware. Not a total surprise of course, because they have teased this offering for a while, and they have actually had the system in customer beta testing for a while. I know, because I wa...
by Eric
0

 




Join Zipcar and get $50 in free driving Join Zipcar and get $50 in free driving Join Zipcar and get $50 in free driving

0 Comments


Be the first to comment!


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>