2 Replies Latest reply on Sep 5, 2012 5:00 AM by Grzesiekk

    upgradeVM_task method question

    Grzesiekk Expert

      Hello,

       

      $myvmid=(get-vm 'myvm').id

      (get-view -id $myvmid).UpgradeVM_Task('vmx-08'

       

      This 2 lines will upgrade virtual hardware in vm to version 8. it works, i tested it. But when i was writing it first, i wrote it like this:

      $myvmid=(get-vm 'myvm').id

      (get-view -id $myvmid).UpgradeVM_Task()

       

      Task was created , no error in powercli console. But error was displayed in VC, saying that this is impossible.

      I read the guide about thie upgradeVM_task and it says:

      Parameters

      NameTypeDescription
      _thisManagedObjectReferenceA reference to the                                VirtualMachine used to make the method call.
      version*xsd:stringIf specified, upgrade to that specified version. If not specified,                 upgrade to the most current virtual hardware supported on the host.

       

      So the parameter version is not needed becase of the " * " next to property version. It should assume vmx-08 by defalut as this is the newest version(esxi 5). This parameter version from what it says  does not require $null , i can ommit it right ? OR this is another example that i should use get_type,get_method,invoke and somehow push $null to it ?

        • 1. Re: upgradeVM_task method question
          Grzesiekk Expert

          Right....

          $id=(get-vm 'myvm').id

          $vmview=get-view -id $id

          $param = @($null)

          $vmview.gettype().GetMethod("UpgradeVM_Task").Invoke($vmview,$param)

          .... 20 minutes of trying and finally did it

           

          #13:52:59> $vmview.gettype().GetMethod("UpgradeVM_Task").GetParameters()

           


          ParameterType   : System.String
          Name            : version
          DefaultValue    :
          RawDefaultValue :
          Position        : 0
          Attributes      : None
          Member          : VMware.Vim.ManagedObjectReference UpgradeVM_Task(System.String)  -> 1 parameter

           

          But this 1 parameter should be in array , so i i wanted to give $null, it should be $param=@($null)

          as per

          Invoke(System.Object obj, System.Object[] parameters)

           

          Can others confirm my thinking ?

          • 2. Re: upgradeVM_task method question
            LucD Guru
            User ModeratorsCommunity WarriorsvExpert

            You stumbled upon a known PowerShell problem.

             

            When a parameter for a SDK method is defined as type [string], you can't use a $null value to indicate that the parameter is not present.

            The only workaround is the Invoke method which will allow you to pass the method parameters as an array. And that way you can use $null to specify the absence of a parameter.

            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz