I need some help removing a single entry from all my vm's vmx files.
The line in question is...
ideX:Y.present=false
I had added that line to all of my vm's vmx file because of security hardening. I need to remove that line because Veeam can't recognize that entry and errors out when a backup is tried.
The original script run was something like this...(just putting up the relavent parts)
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$VMX10e = New-Object VMware.Vim.OptionValue
$VMX10e.Key = "ideX:Y.present"
$VMX10e.Value = "FALSE"
$vmConfigSpec.ExtraConfig += $VMX10e
At the end there is....
$cluster = Get-Cluster $targetcluster | Get-VM %{
$_.Extensiondata.ReconfigVM($vmConfigSpec)
}
Appreciate any help on this
Afaik there is no way, through an API, to remove a line from a VMX file.
But you can blank out a line. See the thread called How to remove an extraConfig setting
An alternative is to use the datastore provider that comes with PowerCLI, find the VMX file, read in the VMX file, remove the line in question and write back the VMX file.
Mind that the VM will have to be powered off and possibly also unregistered.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc,
Thanks for the response....could you please clarify (give and example of how to use) your statement about the datastore provider (I'm very new at this)
or
can the offending entry be modified to just remove the :Y part via powercli?
Thanks
There is a good example of using the datastore provider in my VMX Raiders Revisited post.
In short, first set up the datastore access
New-PSDrive -Name TgtDS -Location $Datastore -PSProvider VimDatastore -Root '\' | Out-Null
Now you can search this new drive, just like any other drive.
Get-ChildItem -Path TgtDS: -Recurse | where {$_.Name -like "*.vmx"}
This will give you all the VMX files on that datastore.
Once you have the VMX file, you read the content (Get-Content), change the lines you want and write the VMX file back (Set-Content).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi guys, sorry to revive this topic!
What if I want to change the KEY name...
I've added a key to all my vmx files with a typo (dammint!) and now I have to correct that.
I was using this approach: http://blogs.vmware.com/vipowershell/2008/09/changing-vmx-fi.html but I've set the $key = "RemoteDisplay.maxConnection" instead of $key = "RemoteDisplay.maxConnections"
Does anyone know a easy way to fix that?
Thanks in advance.
You can blank out an entry, but removing an entry used to be a problem.
See How to remove an extraConfig setting
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That's not what a meant... I need to change the key... My guess is there is no way...
I need something to change de line FROM:
RemoteDisplay.maxConnection2 = "1"
To
RemoteDisplay.maxConnections = "1"
You know? Any helps?
That key can be changed through the numDisplays property in the VirtualMachineVideoCard object.
That is why you can't change it with a KeyValue pair in ExtraConfig.
Alan has a good example in his Change VM Video Memory post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi there! It's not that I couldn't change.. I did... but I've inserted the ExtraConfig with a Typo...
The ones that I correct manually (via vi'ing the vmx file) do work as expected.
Like I said before you can't remove a line via the ExtraConfig.
So you will need to use ReconfigVM to enter the correct line (which will exist next to the incorrectly typed line).
If you really want to remove that line from all the VMX files then the following (but cumbersome) method could be used:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks everyone.
I did it a little better, Logged via SSH on one of the servers and:
I thought that I would be restricted from changing the VM configuration on VCenter (since I didn't unregistered and re-registered the VM) but I tested and any configuration change did actually preserved the correct settings that I've made in the file.
Odd, but was triple-checked by me!
Hope it helps anyone in the future.
Best,
I was able to pull in the vmx item using Get-ChildItem, but Get-Content results in an error: "Get-Content : Cannot use interface. The IContentCmdletProvider interface is not implemented by this provider." Any ideas what that means? I can't find a way to actually display the contents of the vmx file...
I assume the $file variable holds an object returned by Get-ChildItem via the vim provider ?
If yes, that provider doesn't implement the Get-Content cmdlet, that is why you would first have to copy the VMX file to local storage with the Copy-DatastoreItem cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is weird if it did happen. The vmx edits you made would have been overwritten by the version that VC DB has. What does work though is if you follow this:
- power off vm
- edit the vmx file
- reload the vmx file (vim-cmd vmsvc/reload VMID)
- power on the vm