VMware Cloud Community
lldmka
Enthusiast
Enthusiast

Write value to vmx files

Hi,

Complete newbie to the VI Toolkit... but I thought the following (copied from a VI Powershell blog) would write the bios.bootDelay value to my test VMs:

connect-viserver testvc

$key = "bios.bootDelay"

$value = "5000"

get-vm test* | foreach {

$vm = Get-View $_.Id

$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec

$vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue

$vmConfigSpec.extraconfig[0].Key=$key

$vmConfigSpec.extraconfig[0].Value=$value

$vm.ReconfigVM($vmConfigSpec)

}

However it doesn't do anything more than connect to the VirtualCenter server. Any help appreciated.

Reply
0 Kudos
2 Replies
hugopeeters
Hot Shot
Hot Shot

When you dot-source the script (eg type the script name preceded by a dot and a space), you can investigate which variables have which values.

My guess is the $vm is not getting set, because Get-View $_.Id is "the old way". Try replacing that line with $vm = $_ | Get-View

Reply
0 Kudos
LucD
Leadership
Leadership

I think you can't use the extraconfig object to change the BIOS settings this way.

In the extraConfig property of the VirtualMachineConfigSpec object it say:

"Configuration keys that would conflict with parameters that are explicitly configurable through other fields in the ConfigSpec object are silently ignored.".

You will have to use the bootOptions property to change this value.

Something like this:


$value = "5000"
get-vm MVV30* | foreach {
	$vm = Get-View $_.Id
	$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
	$vmConfigSpec.BootOptions = New-Object VMware.Vim.VirtualMachineBootOptions
	$vmConfigSpec.BootOptions.BootDelay = $value
	$vm.ReconfigVM_Task($vmConfigSpec)
}


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

Reply
0 Kudos