vSphere PowerCLI script to add a series of entries to a virtual machine’s .vmx file. You can add entries to the file by using a PowerCLI script with a comma separated values as input.

This script updates .vmx files for all virtual machines in inventory.

You can define the scope by connecting to vCenter Server or limiting the list of virtual machines by connecting to a host when prompted.

To add entries to the .vmx file via PowerCLI:

1. Create a CSV file which uses this format:

Key,Value <—- This header information is necessary for the script to run correctly

log.keepOld,10

log.rotateSize,100000

2. Create a PowerShell (.ps1) script with the following contents:

$vCenter = Read-Host "Enter your vCenter servername or ESXi hostname"Connect-VIServer $vCenter $import = Import-Csv "C:\Scripts\vmxsettings.csv" $vms = Get-View -ViewType VirtualMachine | where {-not $_.config.template}  $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec     foreach($item in $import){          $extra = New-Object VMware.Vim.optionvalue        $extra.Key=$item.Key         $extra.Value=$item.Value         $vmConfigSpec.extraconfig += $extra    }      foreach($vm in $vms){          $vm.ReconfigVM($vmConfigSpec)     }  Disconnect-VIServer –Confirm:$false 

3. Start a vSphere PowerCLI session and execute the script:

PowerCLI C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> C:\Scripts\addvmx.ps1

NOTE: Once added, these entries cannot be removed via the GUI’s configuration parameters screen for each virtual machine. To remove these entries, you may have to edit each .vmx file via SSH.