PowerCLI Update VMware Tools without a reboot.

UPDATE:  This Functionality has been completely replaced with the Update-Tools cmdlet!


 UPDATE: 2009-7-31Recently several individuals have contacted me to report complications using my update-tools script. These issues center around my use, and dependency on WMI, and what appears to be vSphere 4 growing pains. Hopefully, the PowerCLI team can get this functionality built into the VUM cmdlets! Until then some assembly required!


There appears to be a bug in the VMwareToolsUpgrader.exe that will cause the system to reboot no matter what. This behavior is especially bothersome because the VI API simply calls that executable to perform any non-interactive upgrade.

This morning I was updating a smaller farm to 3.5u4. 15 minuets into the tools upgrade process I had enough… Enter PowerShell, I whipped up a quick script that will update All Windows VM’s to the latest version of VMware Tools.

Using this script I updated 50 Vm’s in 40min. There is alot of room for improvement here. I opted for the slow and steady pace, but larger environments could easily tune this to 100 at a time.

~Glenn

P.S. I started with Invoke-VMScript but only half of the vm’s had PowerShell installed, and I needed something that would hit them all.

17 thoughts on “PowerCLI Update VMware Tools without a reboot.”

  1. If I’m reading this right on the web Invoke-Method is only in PS 2.0, which isn’t actually RTM yet. Is there a way to do something similar in PS1?

    Reply
    • sure thing, I made the jump to V2 over a year ago. At this point I couldn’t imagine going back to V1, but I understand not all env are the same 🙂

      # V1 method
      # Create a new process on the VM, and execute setup
      $go = ([wmiclass]"\$($VM.Name)rootcimv2:win32_process").Create($cmd)
      

      The only downside is you lose the ability to pass credentials so you have to run the console as an admin.

      Hope that helps,
      ~Glenn

      Reply
  2. I decided to bump to CTP3 and try 2.0, and I ran that script agains a VM and it uninstalled the tools, but didn’t install. Investigating why, it looks like it uninstalled and unmounted the tools installer, but it didn’t error out. Have you tested this on vSphere 4 yet?

    Reply
  3. Unfortunately, No I haven’t tested against vSphere 4 (it may not be compatible). The cd shouldn’t unmount until tools are reporting a status of ‘toolsOk’. That’s just odd, please let me know if you figure it out!

    Reply
  4. Ok, so as it progresses through the install it removes the tools, then attempts to reinstall but that part throws an error in the eventlog of a MSI installation failure, which may return to the script as a completed installation and it unmounts. It follows the logic like it should. When I manually install the tools I get an error on a driver which I think is the issue. If I can figure that out I’ll let you know.

    Reply
  5. Ok, I think I have it. 4.0 uninstalls the tools then installs the new version rather than upgrading them like it used to. The servers where it uninstalled but didn’t install got prompted during the install and a silent install appears to fail when that happens. Still working on it though.

    Reply
  6. PowerCLI 4.0 Update 1 has a NoReboot option for the Update-Tools cmdlet. You can now do things like:
    Get-VM `
    | Get-View `
    | Where-Object { $_.Config.Tools.ToolsVersion -ne “207095” } `
    | Get-VIObjectByVIView `
    | Update-Tools -NoReboot

    Reply
  7. $starttime = get-date
    #requires -version 2
    $OldTools = Get-View -ViewType “VirtualMachine” `
    -Property Guest,name `
    -filter @{
    “Guest.GuestFamily”=”windowsGuest”;
    “Guest.ToolsStatus”=”ToolsOld”;
    “Guest.GuestState”=”running”
    }

    Foreach ($VM in $OldTools) {
    Get-VM `
    | Get-View | Where-Object { ($_.Guest.GuestFamily -eq “windowsGuest”) -and ( $_.Guest.GuestState -eq “running” ) -and ( $_.Guest.ToolsStatus -eq “ToolsOld” ) } | Get-VIObjectByVIView | Update-Tools -NoReboot
    }
    $processed = $oldTools.count – (Get-View -ViewType “VirtualMachine” `
    -Property Guest,name `
    -filter @{
    “Guest.GuestFamily”=”windowsGuest”;
    “Guest.ToolsStatus”=”ToolsOld”;
    “Guest.GuestState”=”running”
    }).count
    $ts = New-TimeSpan -Start $starttime
    write-host (“{0} out of {1} vm’s were updated in {2}.{3} Min” -f $processed, $oldTools.count, $ts.Minutes,$ts.Seconds)

    Reply
  8. Can we define individual Virtual Machine’s names in the script to upgrade the tools on ? or Rather can we supply a text file containing names of all VMs of which VMTools are to be upgraded.
    Thanks.
    Prakash Kumar

    Reply
  9. Wow, does this still works with vsphere 4.1 ?
    most of my environment is still running Win2k3 and Win2k8

    Reply
    • Have you tried, Get-VM | Update-Tools -NoReboot

      Honestly this script is out of date, as the builtin cmdlet now supports suppression.

      ~Glenn

      Reply
  10. You can use this CLI:

    Get-Cluster “Clustername” | Get-VM | Update-Tools – NoReboot – This will update all VMs within the cluster without rebooting. It will restart NICs instead.

    Reply

Leave a Reply