2 Replies Latest reply on Nov 23, 2008 9:44 PM by lldmka

    Write value to vmx files

    lldmka Hot Shot

      Hi,

       

      Complete newbie to the VI Toolkit... but I thought the following (copied from a VI Powershell blog) would write the bios.bootDelay value to my test VMs:

       

      connect-viserver testvc

      $key = "bios.bootDelay"

      $value = "5000"

      get-vm test* | foreach {

        $vm = Get-View $_.Id

        $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

        $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue

        $vmConfigSpec.extraconfig[0].Key=$key

        $vmConfigSpec.extraconfig[0].Value=$value

        $vm.ReconfigVM($vmConfigSpec)

      }

       

       

      However it doesn't do anything more than connect to the VirtualCenter server. Any help appreciated.

        • 1. Re: Write value to vmx files
          hugopeeters Hot Shot

          When you dot-source the script (eg type the script name preceded by a dot and a space), you can investigate which variables have which values.

          My guess is the $vm is not getting set, because Get-View $_.Id is "the old way". Try replacing that line with $vm = $_ | Get-View

          • 2. Re: Write value to vmx files
            LucD Guru
            User ModeratorsvExpertCommunity Warriors

            I think you can't use the extraconfig object to change the BIOS settings this way.

            In the extraConfig property of the VirtualMachineConfigSpec object it say:

            "Configuration keys that would conflict with parameters that are explicitly configurable through other fields in the ConfigSpec object are silently ignored.".

             

            You will have to use the bootOptions property to change this value.

            Something like this:

            
            $value = "5000"
            get-vm MVV30* | foreach {
                 $vm = Get-View $_.Id
                 $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
                 $vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
                 $vmConfigSpec.BootOptions.BootDelay = $value
                 $vm.ReconfigVM_Task($vmConfigSpec)
            }