There are many tools available on Citrix XenServer which are of use to system administrators and QA analysts look to automate scripts and tests running on XenServer.

These third party tools are usually not officially supported as part of the Citrix XenServer product distribution i.e. we can’t guarantee their ongoing availability and would not offer support for bugs or faults in the tools. As such these tools are often undocumented and I’m learning about new ones all the time.

In practice these tools can be very useful and are of a high quality. This week I saw my colleague Robert using a rather cute little tool (vncsnapshot) to script the taking of screenshots of the screen the user sees within a VM from the host. Our own QA department use this to automatically gather certification results especially when running a large number of VMs on a host and it struck me that others might be interested.

Most of the time XenServer VMs have a VNC stream available. Another of my colleagues has written a blog about using VNC to connect to XenServer which provides useful background, it’s available here, and also describes how to do this remotely via a tunnel. (When GPU pass-through is in use the VNC stream is usually disabled so I’m afraid this technique won’t work, however it should work with vGPU.)


The key commands are:

xe vm-list params=dom-id name-label=<vm-name>

to give you the domain ID.

xenstore-read /local/domain/<domain id>/console/vnc-port

which gives you the VNC port. Subtract 5900 to get the VNC display number to use in the vncsnapshot command thus:

vncsnapshot localhost:<VNC display number> test.jpg


[root@test58 dev]# xe vm-list params=dom-id name-label=xenrt-iscsi-target

dom-id ( RO)    : 1

[root@test58 dev]# xenstore-read /local/domain/1/console/vnc-port


Subtracting 5900, gives a VNC display number of 2 that can now be supplied to the vncsnapshot utility

[root@test58 dev]# vncsnapshot localhost:2 test.jpg

VNC server supports protocol version 3.3 (viewer 3.3)

No authentication needed

Desktop name "XenServer Virtual Terminal"

Connected to VNC server, using protocol version 3.3

VNC server default format:

8 bits per pixel.

True colour: max red 7 green 7 blue 3, shift red 5 green 2 blue 0

32 bits per pixel.

Least significant byte first in each pixel.

True colour: max red 255 green 255 blue 255, shift red 0 green 8 blue 16

Same machine: preferring raw encoding

Image saved from (local host) 640x384 screen to test.jpg using 640x384+0+0 rectangle

[root@test58 dev]#

If you are interested in writing your own scripts to automate bespoke tasks or tests for your own XenServer installation it’s worth remembering that you also have the option to use the XenServer PowerShell cmdlets (or the XenServer C, C#, Java or python APIs) and also to integrate your scripts into the XenCenter GUI via XenCenter plugins. PowerShell is a particularly popular choice with XenDesktop administrators.

I’d also recommend watching my colleague Jesse’s blog; Jesse is a support ninja who often blogs about scripting and tools available on XenServer and other Citrix products.