XenServe VM PowerShell CmdLet

Added by Andy Zhu , last edited by Andy Zhu on Apr 16, 2008  (view change)
Tags: 

Some useful powershell cmdlets for XenServer to create VM, Delete VM and List VM and VMtemplates information.

Description

During the course of using the XenServer, we found it is complicated to use the Xe.exe command line to create, destroy VM, to get VM or VM Template information because XE.exe utility relies heavily on the UUID property used by different XenServer objects.

So we started a journey to implement some of the VM operations in the form of Powershell cmdlet using the existing XenServer API.

XenServer API documentation can be found at http://docs.xensource.com/. CDN site has many examples on using XenServer API. You can browse this link for XenServer SDK wiki

Note: Out Cmdlets assume you use root as user name used to connect to the xenhost.

Currently, we implemented about 7 Powershell cmdlet for XenServer to support our majority of daily tasks involving create VM, remove RM, get VM and Template information etc. Our main goal is to showcase how to utilize the power of Powershell to simplify our handling of XenServer VM. So the cmdlets we implemented does not provide detail help information. The main usage of these cmdlets will be explained here. We will implement the help file in the future.

To use these cmdlets, you need to copy all the contents to a local directory and use the .NETFrame work's installutil.exe utility to install the Xenservercommand.dll file.

After install the DLL, you can then launch the Powershell and use the "Add-PSSnapin XenServerCommandPSSnapin" command to add the XenServer Cmdlet to your Powershell environment.

The following are the list of five main cmdlet currently functions:

Convert-LocalSR <XenHostName> <password>: It accept only one parameter of XenServer name. This Cmdlet will change the local SR of XenServer from LVM type to VHD format so it can support fast cloning of VM. This cmdlet only supports change local storage, not centralized iSCSI storage or NFS storage.

The Covert-LocalSR cmdlet will also accept the IP address as XenHostName parameter. We also originally assume everyone has their default local SR named as "XenhostName-Local Storage". But it might not be case in some installations. Now the cmdlet looking for LVM type of SR on the xenserver and change it to VHD format.

Copy-LocalVM <XenHostName> <password> <VMtemplateName> <VMbaseName> <VMstart#> <VMend#>: This cmdlet will connect to the <XenHostname> and use the <VMtemplateName> provided to start several VM. The new VMs will all have the same basename provided by <VMbasename>, and you can control how many VM you want to create by providing <VMStart#> <VMEnd#>. For example, the following command will create 4 VM on r106x07 XenServer to Start four VM with base name as r106x07: Copy-LocalVM r106x07 LHX64 r106x07 1 4. After the command finish, you will have 4 VM, called r106x07-1,r106x07-2,r106x07-3,r106x07-4. Of course, you need to import a template before running this command. 

Note: The newly created VM will also have its "real" hostname the same as the VM names.

Remove-VM <XenHostName> <password> <VMbaseName> <VMStart#> <VMEnd#>: This command will remove the VM from the XenServer, assuming your VM has the format of <VMBaseName-1>, <VMbaseName-2>, etc. If you do not provide the <VMbaseName>, <VMStart#> and <VMEnd#> parameters, this command will remove all the VM on the <XenHostname>.

Get-VM <XenHostName> <password>: This command will list all the VM and its properties that exist on the <XenHostName>.

Get-Template <XenHostName> <password>: This command will list all the templates that exist on the <XenHostName>.

The cmdlet help file are also included. The Get-Help cmdlet will use that file to provide more information for the cmdlets

All the comments are very welcome. If you find any bugs, please let us know. 

Download

Click here to download

User Rating?

Disclaimer

These software applications are provided to you as is with no representations, warranties or conditions of any kind. You may use and distribute it at your own risk. CITRIX DISCLAIMS ALL WARRANTIES WHATSOEVER, EXPRESS, IMPLIED, WRITTEN, ORAL OR STATUTORY, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NONINFRINGEMENT. Without limiting the generality of the foregoing, you acknowledge and agree that (a) the software application may exhibit errors, design flaws or other problems, possibly resulting in loss of data or damage to property; (b) it may not be possible to make the software application fully functional; and (c) Citrix may, without notice or liability to you, cease to make available the current version and/or any future versions of the software application. In no event should the code be used to support of ultra-hazardous activities, including but not limited to life support or blasting activities. NEITHER CITRIX NOR ITS AFFILIATES OR AGENTS WILL BE LIABLE, UNDER BREACH OF CONTRACT OR ANY OTHER THEORY OF LIABILITY, FOR ANY DAMAGES WHATSOEVER ARISING FROM USE OF THE SOFTWARE APPLICATION, INCLUDING WITHOUT LIMITATION DIRECT, SPECIAL, INCIDENTAL, PUNITIVE, CONSEQUENTIAL OR OTHER DAMAGES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. You agree to indemnify and defend Citrix against any and all claims arising from your use, modification or distribution of the code.

  • Add to Bookmarks