VMware Cloud Community
ws65insd
Contributor
Contributor

Remove a single line entry from vmx file for multiple vm's

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

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership

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

ws65insd
Contributor
Contributor

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

Reply
0 Kudos
LucD
Leadership
Leadership

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

GeraldoMagellaJ
Contributor
Contributor

Hi guys, sorry to revive this topic! Smiley Happy

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
GeraldoMagellaJ
Contributor
Contributor

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?

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
GeraldoMagellaJ
Contributor
Contributor

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.

Reply
0 Kudos
LucD
Leadership
Leadership

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:

  • make sure the VM is powered off
  • unregister the VM
  • use Copy-DatastoreItem to download the VMX file to your PC
  • read the content of the VMX file, skip the faulty line and write the file back
  • upload the VMX file with Copy-DatastoreItem
  • register the VM with the path to the VMX file


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
GeraldoMagellaJ
Contributor
Contributor

Thanks everyone.

I did it a little better, Logged via SSH on one of the servers and:

  1. Turn the VM Down.
  2. Edited the vmx file, correcting the last line.
  3. Turn the VM up again.

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! Smiley Happy

Hope it helps anyone in the future.

Best,

Reply
0 Kudos
lorengordon
Enthusiast
Enthusiast

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...


get-content error.jpg

Reply
0 Kudos
LucD
Leadership
Leadership

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

Reply
0 Kudos
MR-Z
VMware Employee
VMware Employee

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

Reply
0 Kudos