Last week I showed you how to use Set and GetConfigValue to change settings under Virtual Server.  Today I would like to show you another interesting use for this API.  Basically you can use it to extend the virtual machine configuration files to store arbitrary data.  Below is a script that creates a new custom key and stores a value in it:

Set vs = CreateObject("VirtualServer.Application")
set vm1 = vs.FindVirtualMachine(WScript.Arguments(0))

key = "Bens_Test_Key/Some_Value"

Result = vm1.SetConfigurationValue(key, "Hello World")

Wscript.echo "Fetching custom key: " & key & " value: " & vm1.GetConfigurationValue(key)

Now you may be asking why you would want to do this.  The main reason this is here is so that people who are building management software on top of Virtual Server can store any extra information that they need to associate with a virtual machine in an easy and accessible manner.

It should be noted that the key name should not contain spaces or invalid file characters ( \ / and such).

Cheers,
Ben