The below Powershell script is (heavily) based on this Perl script.
It uses a feature that is available with VC2.5 or later and ESX 3.5 or later.
The keyword "bios.bootDeviceClasses" allows to define the boot devices in the VMX file.
Note: this does not allow one to change the boot order !
For more info on the syntax see the Perl script.
The following example sets the boot devices of the virtual machine to the CD drive and the hard disk.
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.extraConfig += New-Object VMware.Vim.OptionValue
$spec.extraConfig[0].key = "bios.bootDeviceClasses"
$spec.extraConfig[0].value = "allow:cd,hd"
(get-view (Get-VM -Name <VM-name>).ID).ReconfigVM_Task($spec)
If you want to force a boot from CD, for example for an OS deployment, only allow the CD device.
Once the OS installation is complete change the allowed boot devices to only the hard disk.