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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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 :
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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")
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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The funny thing is this way work just once
work perfect ,when run it again stopped working .
i will try later
Any error messages ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No there is no error but have a problem when insert some key ,
Is there any reservation in vmx key
About delete contenet of file script working perfect
just you miss Enter between New-psdrive and copy-datastoreitem
Thank you
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure what you mean with the "reservation in vmx key" ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
sorry 4 late again
I think there is no workarroung to enter special key ,
Really i appreciate your help ,
thank you very much .