1 Reply Latest reply on Nov 18, 2019 1:18 AM by LucD

    Update-Tools     : Operation is not valid due to the current state of the objec

    Pilu1978 Enthusiast

      Hi,


      I have wriitten the following script to update VMTools on my Windows VM's. The script is running fine but it is throwing the following error for each and every VM. However it is successfully updating the VMTools on the VM.

       

      17/11/2019 05:11:05 Update-Tools Operation is not valid due to the current state of the object.

       

      $report = @()

      if($VM.ExtensionData.Guest.ToolsVersionStatus -eq "guestToolsNeedUpgrade"){

      Write-Host "Updating VMware tools on $($VM)" -ForegroundColor Green

      Try{

      Update-Tools $VM -ErrorAction Stop -RunAsync

      $vmobj = "" | Select VM, Status

      $vmobj.VM = $VM.name

      $vmobj.Status = "VMTools installed successfully"

      $report += $vmobj

      }

      Catch{

      $vmobj = "" | Select VM, Status

      $vmobj.VM = $VM.name

      $vmobj.Status = $_.Exception.Message

      $report += $vmobj

      }

      }

      $report | Export-csv C:\temp\VMTools-Upgrade-Status.csv -notypeinformation.

       

      I found some workaround mentioned here https://serverfault.com/questions/654415/powercli-move-vm-returns-failure-but-vm-still-moves but not sure how to incorporate the same in my script or is there any other way to resolve it.

       

      Please help.

        • 1. Re: Update-Tools     : Operation is not valid due to the current state of the objec
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          I'm not too sure that the article you referenced is similar to what you are seeing.
          The problem in the article is related to waiting for an async task.
          And like the last entry in that article correctly states, a Task object does not refresh automatically.

           

          Can you try your script, on a limited set of VMs, without the RunAsync switch?
          And check if the error comes again for each VM.

           

          It could also be useful to have a look in the vpxd log to find any additional information on why the error happens.