PowerCLI: Scripted edit of a VMX file

From VI-Toolkit
Jump to navigation Jump to search

Scripted edit of a VMX file

author: Craig Baltzer

Description

Craig shows here how you can adjust keys and values in a scripted manner for the hardware configuration of your virtual machine.

Code

 $vm = Get-View (Get-VM +NameofVMtoUpdate+).ID
 $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
 $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
 $vmConfigSpec.extraconfig[0].Key="lefthandsideofentry"
 $vmConfigSpec.extraconfig[0].Value="rigthhandsideofentry"
 $vm.ReconfigVM($vmConfigSpec)

Where

  • NameofVMtoUpdate is the name of the VM you want to update (from the vCenter inventory)
  • lefthandsideofentry is the advanced configuration entry you want to set
  • rigthhandsideofentry is the value for the advanced configuration entry

Location

VMTN: Scripted edit of a VMX file