Automating virtual machines by checking the thumbnail

One of the biggest challenges with automating virtual machines today is being able to detect that a virtual machine is at a specific place in execution (like waiting at the Windows login screen).  A highly effective way to do this is to do a comparison on the thumbnail image of the virtual machine.  While this is only a 64×48 pixel image it is highly accurate for automation purposes.  Here is a piece of script that will save the thumbnail of a virtual machine to a text file.  Usually the thumbnail data is returned as an array – for convenient storage and comparison the Join() command can be used to turn the thumbnail into a string:

‘This script takes three parameters.  The Virtual Server Host, the virtual machine name and
‘the file name to store the thumbnail data in.  It then saves the current thumbnail data for
‘the selected virtual machine to the specified data file

vsHost = WScript.Arguments(0)
vmName = WScript.Arguments(1)
thumbnailFile = WScript.Arguments(2)

‘Connect to Virtual Server
Set vs = CreateObject(“VirtualServer.Application”, vsHost)

‘Find virtual machine
set vm = vs.FindVirtualMachine(vmName)

Wscript.echo “Saving thumbnail data”

‘Save thumbnail data
Set objFSO = CreateObject(“scripting.filesystemobject”)
Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 2, True)
objTextStream.WriteLine Join(vm.Display.Thumbnail)

While this script function will load a thumbnail and wait for a match:

‘Function to check the for a thumbnail match
Function checkForThumbnailMatch(thumbnailFile)

checkForThumbnailMatch = false

‘Open requested thumbnail file
Set objFSO = CreateObject(“scripting.filesystemobject”)
Set objTextStream = objFSO.OpenTextFile(thumbnailFile, 1, True)
savedThumbnail = objTextStream.ReadLine

   ‘Poll for matching thumbnail
   do until savedThumbnail = Join(vm.Display.Thumbnail)

checkForThumbnailMatch = true

end Function

This is very handy – and we have been able to use this internally to automate a variety of things – like complete operating system installations.