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
Anything in the VPXD logs ? Accessible from the vSphere client <Home><System logs>
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
script started...
StartTime : 3/5/2012 1:38:50 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.
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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...
Perhaps it would be useful if you attach the script you are using
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Here's what I'm testing with....
$a = Get-Folder "FolderName"
$Cluster="ClusterName"
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...
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
So this will not change the keys of a vmx file ??
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 ?
I also found it here:
http://blogs.vmware.com/vipowershell/2008/09/changing-vmx-fi.html
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).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
I have tried this script but it does not work properly. or may I did some things mistake?
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?
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference