Automation

 View Only
Expand all | Collapse all

Cannot seem to edit vmx file using following script

  • 1.  Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 07:19 PM

    I am relatively new to using powercli and I am trying to write our DR script.  This will include needing to edit the vmx file to use a replacement disk.  I found the script on the following link, but it doesn't seem to work any more.  I SWEAR it worked once.  When I try now I don't get any errors from what I've got, and it just doesn't do what I want it to.  Is there a log of any sort that I can look at to find out what is going on with this?

    http://www.vi-toolkit.com/wiki/index.php/PowerCLI:_Scripted_edit_of_a_VMX_file



  • 2.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 07:31 PM

    Anything in the VPXD logs ? Accessible from the vSphere client <Home><System logs>



  • 3.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 08:10 PM

    script started...

    StartTime               : 3/5/2012 1:38:50 PM

    log file shows error.... 
    [2012-03-05 13:38:52.447 07732 warning 'App' opID=HB-host-15990@105219] [VpxdMoHost::GetLinkedVmInt] Getting linked vm for vmid 178 on host %servername% - COULD NOT FIND IT
    then something about a port group not found......
    I wonder....   the network will also be changing for this machine as well.  that part of the script is working.  Will that have to work first before this will work ??


  • 4.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 08:14 PM

    No, I just tried to put in a portion to change VLAN, then do the vmx file edit and it doesn't work either.



  • 5.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 08:16 PM

    I wonder, did you refresh the contents of the $vm variable after the network and/or VLAN changes ?

    In other words did you do a new

    $vm = Get-VM MYVM



  • 6.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 05, 2012 08:33 PM

    doesn't that get done when it does a "$vm = Get-View (Get-VM servername).Id"  in the script that I posted link to  ?

    I'll try and do a Get-VM servername after I add to inventory, after I reconfigure the VLAN, and before I run the script I posted...  for grins...



  • 7.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 07:21 AM

    Perhaps it would be useful if you attach the script you are using



  • 8.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 01:19 PM

    Here's what I'm testing with....

    $a = Get-Folder "FolderName"

    $Cluster="ClusterName"

    New-VM -VMFilePath "%path% with %filename%" -VMHost (Get-Cluster $Cluster | Get-VMHost ESXHOSTNAME | Select-Object -first 1) -Location $a[1] -RunAsync
    sleep -seconds 10
    Set-NetworkAdapter -NetworkAdapter ( Get-NetworkAdapter servername ) -NetworkName "VLAN NAME" -StartConnected $false -confirm:$false
    sleep -seconds 10
    $vm = Get-VM servername
    sleep -seconds 10
    <#  last part  #>
    $key = "scsi0:8.filename"
    $value = "/vmfs/volumes/ReplacementDiskNumber/servername/servername.vmdk"
    $vm = Get-View (Get-VM servername).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)

    First part seems to work fine, it adds machine to inventory

    Second part works fine, adds correct vlan

    last part, not so much.  I have used the $value from a vmx file that has been built manually thru removing and adding the disk via the gui.  I can relace the vmx file, but think that being able to edit a vmx file like this will be benificial in the future...



  • 9.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 01:55 PM

    You can't use this method to change values in the VMX file that can also be changed with other methods.

    In this case you are trying to change the backing filename with the ReconfigVM_Task method.



  • 10.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 02:17 PM

    So this will not change the keys of a vmx file ??

    <#  last part  #>
    $key = "scsi0:8.filename"
    $value = "/vmfs/volumes/ReplacementDiskNumber/servername/servername.vmdk"
    $vm = Get-View (Get-VM servername).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)

    I was merely following the following link ....

    http://www.vi-toolkit.com/wiki/index.php/PowerCLI:_Scripted_edit_of_a_VMX_file

    Is this not correct ?



  • 11.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 02:18 PM


  • 12.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 02:22 PM

    The  ReconfigVM method to change VMX entries will work, but not for all entries in your VMX file.

    If the entry is changable by another method, it will most probably not work this way (at least that is my experience).



  • 13.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 03:46 PM

    So what you're saying is that in your experience is that if the value can be changed via the GUI, then it will likely not be able to be changed via PowerCLI, correct?



  • 14.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 05:04 PM

    No, not the GUI.

    If the property can be changed through one of the API methods, it will most probably not work through the ExtraOptions method.

    These API methods are in fact what is underneath the PowerCLI cmdlets.

    The VirtualMachineConfigInfo object is the one that holds all the config values for a VirtualMachine.

    The ExtraConfig property is exactly that, an extra to configure all the values in the VMX file that are not accessible through other properties in the VirtualMachineConfigInfo object.



  • 15.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 05:06 PM

    The modifications which I was attempting to make are not available in the GUI while the VM's are running.  I was trying to edit the advanced configurations.  Regardless if you are using the GUI or hacking the .vmx file, in my experience the VM had to be powered off.



  • 16.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 05:12 PM

    That is correct, for most of the VMX entries the VM needs to be powered off.

    And sometimes even unregistered from the vCenter.

    If you power off a VM it will save the in-memory settings to the VMX file, and the changes you made will most probably be overwritten.



  • 17.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 03:20 PM

    I've never edited the .vmx file using PowerCli but I did notice that in order for manual edits to work I had to have the VM powered off and sometimes I had to remove the vm from and readd it to the inventory.

    If this method works, I'll be one happy camper.

    jd



  • 18.  RE: Cannot seem to edit vmx file using following script

    Posted Mar 06, 2012 03:41 PM

    I have tried this script but it does not work properly. or may I did some things mistake?

    abirhasan