Really Easy Ways to Capture VM Screenshot
Since vSphere 2.5, there is a feature allowing you to capture screen shot of a running virtual machine. It’s not well publicized but you can find a short description with screenshotSupported (boolean) in the HostCapability data object. Thanks to Nikita for bringing this up in the comment of the vSphere Java API 2.1 GA post.
Indicates whether the screenshot retrival over https is supported for this host’s virtual machines. If true, a screenshot can be retrieved at the HTTPS relative path /screen?id=<managed object ID of virtual machine or snapshot>. If any of the optional parameters ‘top’, ‘left’, ‘bottom’, and ‘right’ is specified, the returned image will be cropped from the rectangle with upper left corner (left, top) and bottom right corner (right – 1, bottom – 1). These values default to the top, left, bottom and right edges of the image. The client must use an authenticated session with privilege VirtualMachine.Interact.ConsoleInteract on the requested virtual machine or, in the case of a snapshot, the virtual machine associated with that snapshot.
Time to learn how to "Google" and manage your VMware and clouds in a fast and secureHTML5 App
The managed object ID of virtual machine is the value of ManagedObjectReference, which can be easily found using MOB.
Once you have it, you can issue a URL as follows in any browser and get the screen shot in PNG format.
Supposedly you can also get the screenshot of a snapshot using a URL like the following:
It took a long time before I canceled it. So I was not able to make it working. I also tried top/left/bottom/right with no luck. If you make it working, please feel free to share here.
You cannot use the above URL with a vCenter server which manages the host running the VM. The following URL gets you an error saying the webpage cannot be found.
So capturing screen shot with URL is a host only feature.
In addition to this, you can also use the CreateScreenshot_Task() defined with VirtualMachine type. It works only with ESX(i) as well. The location of the screenshot image file is returned in the Task’s info.result sub-property upon success.
You can have multiple screen shots captured with number incremented as you can find with Web based datastore browser:
MyVM-screenshot-0.png 07-Sep-2010 04:01 292561 MyVM-screenshot-1.png 07-Sep-2010 04:07 292561
As you know to download a file from datastore using HTTP access, you need a URL pattern as follows:
Now the question is: how to convert the above UUID in the info.result to the corresponding datastore’s name. It’s relatively easy task, I would leave it to you. Hint: check out the datastore property of HostSystem type.