5 Replies Latest reply on Sep 29, 2017 11:16 AM by jvm2016

    upgrade vmware tools_powercli

    jvm2016 Expert

      Hi Luc/All,

       

      could you check the following code to upgrade vmware tools .

      blue color is giving output of all vms depending on nested properties .

      However i want to add further "if" logic (red color) in order to get specific vm(shccertvsr01 )only  where vmware tools upgrade is needed but its looping to entire vm list.is this not the right place to put if statement.

       

       

      $conn=$global:defaultviserver

       

      $vc = @("tcclabc002vctt01.servers.chrysler.com","shccertvcs01.shdc.chrysler.com")

      if ($conn -eq $null)

      {

      write-host "connecting to" $vc

      Connect-VIServer -Server $vc -user "administrator@vsphere.local" -password ""

      }

      else{

      write-host "powercli is connected "

      }

       

       

       

      $vm_names=get-cluster shccert|get-vmhost|get-vm

       

       

      foreach ($vm in $vm_names)

      {

      Get-VM $vm | select Name,@{N='Tools status';E={$_.extensiondata.guest.toolsstatus}},@{N="Tools Version Status";E={$_.extensiondata.guest.toolsversionstatus}},@{N="tools running status";E={$_.extensiondata.guest.toolsrunningstatus}}

       

      if ($vm.extensiondata.guest.toolstatus -ne "toolsOK")

      {

      write-host "update the vmware tools of" $vm

      Get-VMGuest $vm | update-Tools -NoReboot

      }

       

      }

       

      disconnect-viserver "*" -force -confirm:$false

        • 1. Re: upgrade vmware tools_powercli
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Not 100% sure I get the question, but you can use a Where-clause to limit the VMs that enter the ForEach loop.

           

          foreach ($vm in (Get-Cluster shccert|Get-VM | where{$_.extensiondata.guest.toolstatus -ne "toolsOK"}))

          {

              $vm | select Name,@{N='Tools status';E={$_.extensiondata.guest.toolsstatus}},

                      @{N="Tools Version Status";E={$_.extensiondata.guest.toolsversionstatus}},

                      @{N="tools running status";E={$_.extensiondata.guest.toolsrunningstatus}}

          }

           

          In fact you can leave out the ForEach altogether

           

          Get-Cluster shccert|Get-VM | where{$_.extensiondata.guest.toolstatus -ne "toolsOK"} |

          select Name,@{N='Tools status';E={$_.extensiondata.guest.toolsstatus}},

                      @{N="Tools Version Status";E={$_.extensiondata.guest.toolsversionstatus}},

                      @{N="tools running status";E={$_.extensiondata.guest.toolsrunningstatus}}

           

          1 person found this helpful
          • 2. Re: upgrade vmware tools_powercli
            jvm2016 Expert

            Thnaks.where-clause can be used .

            • 3. Re: upgrade vmware tools_powercli
              jvm2016 Expert

              so i modified like below.    can i use -whatif in  blue color line as tab does not work .

               

               

              $vmtoupdate=Get-Cluster TCC003 | Get-VM | where{$_.extensiondata.guest.toolsversionstatus -ne "guesttoolscurrent"}

              foreach ($vm in $vmtoupdate)

              {

               

              Get-VMGuest $vm | update-Tools -NoReboot

              }

               

               

               

              Thanks for your support.

              • 4. Re: upgrade vmware tools_powercli
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                I'm afraid Update-Tools does not support WhatIf.

                • 5. Re: upgrade vmware tools_powercli
                  jvm2016 Expert

                  Thanks.