Setting the BIOS boot order programmatically under Virtual Server

I while ago I talked about how to change the boot order in the BIOS by editing the VMC file – and just recently my co-worker, John Howard, pointed out that this could be done programmatically using GetConfigurationValue.  GetConfigurationValue and SetConfigurationValue are two interesting (and really quite powerfull) APIs – and I will probably post about this more in the future.  In the mean time I thought it would be a good idea to provide a sample script:

Set vs = CreateObject(“VirtualServer.Application”)
set vm1 = vs.FindVirtualMachine(WScript.Arguments(0))
set vm2 = vs.FindVirtualMachine(WScript.Arguments(1))

key = “hardware/bios/cmos”

result = vm2.SetConfigurationValue(key, vm1.GetConfigurationValue(key))

This script takes two virtual machines as command line parameters and copies the BIOS configuration from one to the other.  Note – the reason why I am copying this between virtual machines (rather than loading a preconfigured value) is that the CMOS key is actually a byte value – which is really quite hard to manage under VBScript.