Coding Corner: A basic Virtual Server script
Due to reader demand - I am going to try and start a 'coding corner' where I talk about programming to Virtual Server's COM API. For those that don't know - Virtual Server is completely driven via COM - and anything that you want to do with Virtual Server can be done programatically.
We are going to start things off slowly with a very simple VBScript. This script will:
- Create a connection to Virtual Server
- Get a collection of all the virtual machines
- Iterate over the collection and display some basic information about each virtual machine
'Script Begins
On Error Resume Next
'Connect to Virtual Server
Set virtualServer = CreateObject("VirtualServer.Application")
'Get collection of virtual machines
set vmCollection = virtualServer.VirtualMachines
'Iterate over the virtual machines and display data
For Each vm in vmCollection
Wscript.Echo "=============================="
Wscript.Echo "Name: " & vm.Name
Wscript.Echo
Wscript.Echo "Notes: " & vm.Notes
Wscript.Echo
Wscript.Echo "Configuration File: " & vm.File
Wscript.Echo "Saved state file: " & vm.SavedStateFilePath
Wscript.Echo
Wscript.Echo "Guest OS: " & vm.GuestOS
Wscript.Echo "Memory: " & vm.Memory
Wscript.Echo "Undo disks enabled: " & vm.Undoable
Wscript.Echo
Wscript.Echo "=============================="
Next
'Script Ends
As you can see this is really quite simple - but don't worry - we will get more complex as we go on.
Cheers,
Ben