Monday 11 November 2013

How to know on which XenServer host VMs are running


Load-balancing and High Availability are great XenServer features, however, for various reasons, you might want to check on which host which VM is running, and to have the ability to automate the task.

The following powershell script has been created for the XenServer 6.2, using the following XenServerPSSnapin: XenServerPSSnapIn-6.2.0-1.msi

This script does work the same way with previous versions but the cmdlets names changed (e.g.: Get-XenVM was Get-XenServer:VM...).

# Import the XenServer PSSnapIn
Add-PSSnapIn XenServerPSSnapIn

# Connect to the XenServer pool
Connect-XenServer -Server "IP of the poolmaster" -Username "root" -Password "password" -SetDefaultSession

# Retrieve the information
Get-XenVM | ? {$_.is_a_snapshot -eq $false -and $_.is_a_template -eq $false -and $_.is_control_domain -eq $false -and $_.power_state -eq 'running'} | Select-Object name_label, @{Name="hostname";Expression={(Get-XenHost -ref $_.resident_on).hostname}}

# Disconnect from the XenServer pool
Get-XenSession -Server "IP of the poolmaster" | Disconnect-XenServer

1 comment:

  1. Hi

    I am trying to fetch OS version as well for the vms can you please help me how can i retrieve OS version information.

    I have tried Get-xenvmguestmetrics |select OS_version

    but i am not sure how can i integrate it with your script.

    Can you please help me.

    ReplyDelete