ftfcu
Contributor
Contributor

Trying to read vmx file looking for a certain value

Jump to solution

We had a third party deployment go bad.  They add some lines to the vmx files and those lines are causing NICS to disconnect and not reconnect.  We have close to 500 virtual machines and so I am trying to loop through all the VMs looking for a value.

I have been playing around with Get-AdvancedSetting and I can get the values I am looking for, but I cant get the affected VM Name to appear as well.

For example:

Get-AdvancedSetting -Entity (Get-vm) -Name ethernet0.filter0.name

Name                 Value                Type                 Description
----                 -----                ----                 -----------
ethernet0.filter0... vtap_vmkern          VM
ethernet0.filter0... vtap_vmkern          VM
ethernet0.filter0... vtap_vmkern          VM
ethernet0.filter0... vtap_vmkern          VM
ethernet0.filter0... vtap_vmkern          VM

It only returns the name and value of the AdvancedSetting, I cant figure out how to include the server name.

Ultimately I will need to write a script to remove the affected lines, but for now, I want to just get a list of the VMs that have the lines present.

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

You could do something like this

foreach($vm in Get-VM){

     Get-AdvancedSetting -Entity $vm -Name ethernet0.filter0.name |

     Select @{N="VM";E={$vm.Name}},Name,Value,Type

}


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

View solution in original post

5 Replies
LucD
Leadership
Leadership

You could do something like this

foreach($vm in Get-VM){

     Get-AdvancedSetting -Entity $vm -Name ethernet0.filter0.name |

     Select @{N="VM";E={$vm.Name}},Name,Value,Type

}


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

View solution in original post

ftfcu
Contributor
Contributor

@LucD

Thanks for the script, it did just want I needed it to, but looking into the results I have some anomalies, maybe you can help with.


Here are the three lines in the .vmx file causing problems

ethernet0.filter0.name ="vtap_vmkern"

ethernet0.filter0.onFailure ="failClosed"

ethernet0.filter0.param0 ="FAA=EQAAEgATAQEhovAECiAB"

I ran your script and it listed out about 100 machines, which seems about right.  The odd thing is that it listed a machine that I know I manually edited the .vmx file yesterday.  So I double checked the .vmx file of the affected computer again and there is not a line for ethernet0.filter0.name, yet it showed up on your script.  Could advanced sesttings be stored somewhere else as well?

0 Kudos
LucD
Leadership
Leadership

That is a known phenomena.

The Get-AdvancedSetting cmdlet gets the values from the VM itself, not the VMX file.

So I guess this VM was powered on while you updated the VMX ?

And don't forget that when you poweroff the VM it will write a number of configuration settings to the VMX file.

So you risk that your changes to the VMX file will disappear the moment you poweroff the VM.


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

0 Kudos
ftfcu
Contributor
Contributor

It is very possible the vm was on.  This issue took down a large chunk of our production environment last night so multiple people were shutting down vms, using VI, or WINSCP to edit vmx files manually.

So to clear this up, we need to shut down the affected vms and then restart them.  Then rerun the script to see what servers are affected.

From that list, shut them down, make sure they are off.  Edit the files.  Boot them back up.

Does that sound correct?

0 Kudos
LucD
Leadership
Leadership

To query the current settings, you can check with the lines above.

But why do you edit the VMX file directly, that is only required for those settings that are not accessible through the vSphere object method.

In this case you should be able to use the Set-AdvancedSetting cmdlet to change the values.

But it will require a shutdown of the VM to get the new settings in the VMX file afaik.

You could try this out easily with a test VM I assume


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

0 Kudos