VMware Cloud Community
mrchainsaw
Enthusiast
Enthusiast
Jump to solution

Need to remove advanced values from VMX file

Previous administrator elected to harden the VMX files of all VMs to prevent unwanted downtime from individuals installing VMware tools upgrades manually.

I agree with him and understand in prior versions it was a good idea to disable such but now with 5.1 with the fact we no longer have to reboot for tools upgrades to occur my life has become much more complicated and we constantly run into issues with VMs having tools mounted and no way to force unmount tools.

I am looking for a PowerCLI script to removed these advanced values from the VMX file for all VMs attached to a vCenter. I assume they are the following values:

isolation.tools.autoInstall.disable = true

isolation.tools.guestInitiatedUpgrade.disable = false

isolation.tools.connectable.disable=true

If there are any other values I should check, please let me know and I will review the VMX file.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That is another option, but the lines will stay in the VMX, albeit with other values

You could do that with this script

$vm = Get-VM -Name MyVM

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo

$extra1 = New-Object VMware.Vim.OptionValue
$extra1.Key = "isolation.tools.autoInstall.disable"
$extra1.Value = "false"
$spec.ExtraConfig += $extra1
$extra2 = New-Object VMware.Vim.OptionValue
$extra2.Key = "isolation.tools.guestInitiatedUpgrade.disable"
$extra2.Value = "true"
$spec.ExtraConfig += $extra2
$extra3 = New-Object VMware.Vim.OptionValue
$extra3.Key = "isolation.tools.connectable.disable"
$extra3.Value = "flase"
$spec.ExtraConfig += $extra3

$vm.ExtensionData.ReconfigVM($spec)


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

View solution in original post

0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik there is no API to remove lines from a VMX file.

The next best thing is to download the VMX file, edit it and then upload it again.

Your VM needs to be powered off.

Something like this does that

$vmName = "MyVM"
$tgtFolder = $env:Temp
$tgtStrings = 'isolation.tools.autoInstall.disable|isolation.tools.guestInitiatedUpgrade.disable|isolation.tools.connectable.disable'

Get-VM -Name $vmName | %{
 
$dsName,$vmxPath = $_.ExtensionData.Config.Files.VmPathName.Split()
 
$vmxName = $vmxPath.Split('/')[-1]
 
$vmxFolder = [string]::Join('/',($vmxPath.Split('/')[-99..-2]))
 
$dsName = $dsName.Trim('[]')
 
$ds = Get-Datastore -Name $dsName
 
New-PSDrive -Location $ds -Name DS -PSProvider VimDatastore -Root "\" | Out-Null
 
Copy-DatastoreItem -Item "DS:$vmxPath" -Destination $tgtFolder
  (
Get-Content "$tgtFolder\$vmxName") |
   
where {$_ -notmatch $tgtStrings} |
   
Set-Content "$tgtFolder\$vmxName"
 
Copy-DatastoreItem  -Item "$tgtFolder\$vmxName" -Destination "DS:$vmxFolder"
 
Get-ChildItem -Path "$tgtFolder\$vmxName" | Remove-Item -Confirm:$false
 
Remove-PSDrive -Name DS -Confirm:$false
}

The script downloads the VMX file to your Temp directory, makes the changes and then uploads it again to the datastore


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

0 Kudos
mrchainsaw
Enthusiast
Enthusiast
Jump to solution

I should note that this change needs to be completed on roughly 3500 VMs. What if I changed the values to the following?

isolation.tools.autoInstall.disable = false

isolation.tools.guestInitiatedUpgrade.disable = true

isolation.tools.connectable.disable=false

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is another option, but the lines will stay in the VMX, albeit with other values

You could do that with this script

$vm = Get-VM -Name MyVM

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.tools = New-Object VMware.Vim.ToolsConfigInfo

$extra1 = New-Object VMware.Vim.OptionValue
$extra1.Key = "isolation.tools.autoInstall.disable"
$extra1.Value = "false"
$spec.ExtraConfig += $extra1
$extra2 = New-Object VMware.Vim.OptionValue
$extra2.Key = "isolation.tools.guestInitiatedUpgrade.disable"
$extra2.Value = "true"
$spec.ExtraConfig += $extra2
$extra3 = New-Object VMware.Vim.OptionValue
$extra3.Key = "isolation.tools.connectable.disable"
$extra3.Value = "flase"
$spec.ExtraConfig += $extra3

$vm.ExtensionData.ReconfigVM($spec)


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

0 Kudos
julienvarela
Commander
Commander
Jump to solution

HI LucD,

Maybe he can edit his vmx from his host using SSH. You can edit the VMX when your are connecting directly on the host who is running the VM.

So maybe a .ksh will do the job. But then a reboot will be requiered. But this can be planned.

Why do you think about this LucD?

Regards,

Julien.

Regards, J.Varela http://vthink.fr
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is a third option, provided SSH access to the ESXi is not disabled.

But needlessly complex imho; from a PowerCLI session start a SSH session, in which you run a shell script.

And I'm pretty sure a security officer will not like the SSH method since it involves enabling SSH :smileygrin:

I only use SSH as a last resort when there are no other alternatives.


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

0 Kudos
julienvarela
Commander
Commander
Jump to solution

I understand but if he has 3500 VMs, it is very complicated , i guess, to plan a shutdown for running a script no? So using ssh, if he can edit the vmx without downtime, and later plan a reboot.

That's why i was proposing this solution.

Regards,

Julien

Regards, J.Varela http://vthink.fr
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Afaik, that won't help.

When the VM is powered on while you edit the VMX file, chances are the VMX file will be overwriten on the next power off.

That is why I mentioned that the VM needs to be powered off.

In fact to be completely sure the changes are kept, you should even unregister the VM before editing the VMX with any of these methods.

But since the entries we are changing are not kept in the vCenter DB afaik, I skipped that requirement.


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

0 Kudos
rajunellur
Contributor
Contributor
Jump to solution

Veeam Backup are getting failed due to below error

" Error:Failed to parse":Y.present"

need to remove the ideX:Y.present,FALSE entry from .vmx file on multiple VMs

Is there any way to do this.

Thanks

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you already have a look at Remove a single line entry from vmx file for multiple vm's


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

0 Kudos