Automate tasks with use of XenServer Powershell Module

Working with backups of your virtual machines is obviously essential. Working with exports in XenServer can some times be time consuming, particularly with bigger virtual disks attached to your virtual machine. In this scenario I will show you an alternative to manually export via XenCenter, by doing it with Powershell to an remote server using XenServer Powershell module.

XenServer Powershell module

In case you don’t have XenServer Powershell module installed, which is the only prerequisite for connection to XenServer API via Powershell, you can download the XenServer Software Develop Kit from this link (requires an account). The package download also contains a ”readme” file with instructions for configuring the XenServer PowerShell module. Assuming you now have XenServer Powershell Module installed, let’s gets started.

In this scenario, I want to store the virtual machine exports on a separate Windows Server dedicated for backups. I will show you how this can be done for both running and non-running virtual machines.

Create an encrypted password file

Let’s start off with creating an encrypted a password file. This only serves a purpose of not having clear-text password in your script. Clear-text variables containing your username and password works fine as well. Creating a encrypted password file only has to be done once and the password file can be reused for you next script.

Note: The password file can only be read and used by the account who created it, so whether you plan to use the script as a scheduled task in Windows for automated exports, you can for an example create the password file as a service-account.

Connect to your XenServer

We are now going to get a connection established with your XenServer host.

Export a running virtual machine

When performing ”hot-backup” we will need a temporary snapshot. Below can be used for exporting a running virtual machine:

Export a non-running virtual machine

When exporting a shut down virtual machine, we don’t need a snapshot as XenServer handles that itself. Below can be used for exporting a shut down virtual machine:

You can see progress done in your export by connecting to your XenServer via SSH and type the command xe task-list.

Progress of a VM export done with XenServer Powershell Module.

As your XenServer export procedure now is done with a Powershell script, it comes in handy for automation. You can for example use Windows Task Scheduler for automation of your newly built Powershell script.

If you have any questions, feel free to email me at

Disclaimer: All information on this blog is offered "as is" with no warranty. It is strongly recommended that you verify all information and validate all scripts in isolated test environments before using them in production environments.