Automation

 View Only
Expand all | Collapse all

how can modify/change key in VMX file

  • 1.  how can modify/change key in VMX file

    Posted Dec 23, 2012 08:14 PM

    Hi ,

    How can modify or change specific key in VMX file

    i need help with modify  not add  since "Configuration keys that would conflict with parameters that are  explicitly configurable through other fields in the ConfigSpec object  are silently ignored."

    Thanks



  • 2.  RE: how can modify/change key in VMX file

    Posted Dec 23, 2012 09:21 PM

    Which specific key(s) did you have in mind ?

    The text you quote means to say that you can't use this methods when there is a property in a configuration spec that controls the value of a specific VMX file entry.

    The VMX entries that are configurable (add & edit) this way, can be set through the reconfigVM_Task method and the extraConfig property.

    See for example Steve Jin's post called How to Change VMX Programmatically?

    There are several examples in this community as well.



  • 3.  RE: how can modify/change key in VMX file

    Posted Dec 23, 2012 09:27 PM

    Actually i want to edit this key ethernet9.present = "FALSE" and change it toTRUE

    and i already see this post before but didn't understand it



  • 4.  RE: how can modify/change key in VMX file

    Posted Dec 23, 2012 11:04 PM

    Afaik, that VMX key can not be changed through the ExtraConfig property.

    If I understand correctly, you want to remove a NIC that is present on the VM(s).

    Do you have the NIC type or NIC label for the NIC that needs to be removed ?

    If yes, it would be a lot simpler to use the Remove-NetworkAdapter cmdlet.

    Something like this


    Get-VM
    -Name MyVM |
    Get-NetworkAdapter -Name "Network adapter 2" |
    Remove-NetworkAdapter -Confirm:$false

    If you want, you can first have a look at the NICs connected to that VM as follows

    Get-VM -Name MyVM | Get-NetworkAdapter

    If you want to add a NIC, you will have to use the New-NetworkAdapter cmdlet.

    Something like this

    Get-VM -Name MyVM | 
    New-NetworkAdapter
    -NetworkName portgroupname -Type vmxnet3 -Confirm:$false


  • 5.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 06:47 AM

    ok i will will explain more , i have Vnic before in my setup  , after i delete them i get the key ethernet2.present with value FALSE  .

    i want to add NIC but manually using VMX file key

    so before add the new nic i have to change the value from FALSE to TRUE or simply to delete this line .

    for add new vkey with value i am using these command :

    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $spec.extraConfig += New-Object VMware.Vim.OptionValue
    $spec.extraConfig[0].key = "xxx.yyy.zzz"
    $spec.extraConfig[0].value = "xxxxxxxxx"
    (get-view (get-vm -name VM).ID).ReconfigVM_Task($spec) 


  • 6.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 09:45 AM

    I fail to see the reason why you want to do this at all ? That line is there for historic reasons and doesn't have any effect in a vSphere environment afaik.

    But this is one way of remving that line from the VMX file:

    $vm = Get-VM -Name MyVM
    $datastorename,$filepath = $vm.ExtensionData.Config.Files.VmPathName.split(" ")
    $datastorename = $datastorename.TrimStart("[").TrimEnd("]")
    $filename = $filepath.Split('/')[-1]
    $oldvmx = $env:temp + "\" + $filename 
    $newvmx
    = $env:temp + "\new" + (Get-Random -Maximum 1GB) + ".vmx"
    $ds = Get-Datastore -Name $datastorename
    Remove-VM
    -VM $vm -Confirm:$false
    New-PSDrive
    -Name ds -PSProvider VimDatastore -Root '/' -Location $ds Copy-DatastoreItem -Item "ds:\$($filepath)" -Destination $oldvmx
    Get-Content
    $oldvmx | where {$_ -notmatch "ethernet9.present"} | Set-Content $newvmx
    Copy-DatastoreItem
    -Item $newvmx -Destination "ds:\$($filepath)" -Force -Confirm:$false Remove-PSDrive -Name ds
    New-VM
    -VMFilePath $vm.ExtensionData.Config.Files.VmPathName -VMHost $vm.Host -Confirm:$false


  • 7.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 09:52 AM

    Thank you very much , i will use it and update you ,

    i have another quis about add key

    i faced problem with add value , althought test finished successfully but there is no key added to VMX file

    Script :

    $key = @("key1","key2","key3")

    $value = @("value1","value2","value3")
    $vms=Get-VMHost 10.136.138.1 | get-vm -name qa-l-vrt-138-009| get-view
    $i=0
    while ($i -le 2) {
         $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
         echo $key[$i]
         echo $value[$i]
         $extra = New-Object VMware.Vim.optionvalue
         $extra.Key=$Key[$i]
         $extra.Value=$Value[$i]
         $vmConfigSpec.extraconfig += $extra
         $vms.ReconfigVM($vmConfigSpec)
         $i++
    }

    and on another ESX (VM) i get this error

    Method invocation failed because [System.Object[]] doesn't contain a method named 'ReconfigVM'.

    At C:\Users\Administrator\AppData\Local\Temp\f68d3192-a31f-4e1d-8c4d-43d9543da076.ps1:22 char:16

    + $vms.ReconfigVM <<<< ($vmConfigSpec)

        + CategoryInfo          : InvalidOperation: (ReconfigVM:String) [], RuntimeException

        + FullyQualifiedErrorId : MethodNotFound



  • 8.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 11:09 AM

    It looks as if the Get-VM returned more than 1 VM, that makes that $vms is an array.

    You can check with

    Get-VMHost 10.136.138.1 | get-vm -name qa-l-vrt-138-009

    The ReconfigVM method is not known on an array.



  • 9.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 12:06 PM

    The funny thing is this way work just once :smileyhappy:

    work perfect ,when run it again stopped working .

    i will try later



  • 10.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 12:20 PM

    Any error messages ?



  • 11.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 04:18 PM

    No there is no error but have a problem when insert some key ,

    Is there any reservation in vmx key



  • 12.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 05:01 PM

    About delete contenet of file script working perfect

    just you miss Enter between New-psdrive and copy-datastoreitem

    Thank you



  • 13.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 07:22 PM

    I think that missing CR-LF might be the interaction between Jive forum SW, on which the VMTN Community is running, and IE browsers.

    We often see CR-LF being dropped when doing a copy/paste.

    Alternative browsers (FF, Opera...) don't seem to have this problem.



  • 14.  RE: how can modify/change key in VMX file

    Posted Dec 24, 2012 07:23 PM

    Not sure what you mean with the "reservation in vmx key" ?



  • 15.  RE: how can modify/change key in VMX file

    Posted Jan 08, 2013 07:50 AM

    sorry for late

    for example i want to insert this key and value

    $key = "ethernet2.dvs.switchId"
    $value = "78 76 6c 61 6e 5f 76 64-73 00 00 00 00 00 00 00"

    but nothing modified into VMX file , any other $key  work fine



  • 16.  RE: how can modify/change key in VMX file

    Posted Jan 08, 2013 08:20 AM

    The settings that can be done through through other means can not be done through the VMX file entries.

    In this case the setting is created when you assign the NIC with a portgroup to the VM.



  • 17.  RE: how can modify/change key in VMX file

    Posted Jan 16, 2013 07:04 AM

    sorry 4 late again

    I think there is no workarroung to enter special key ,

    Really i  appreciate your help ,

    thank you very much .