PowerShell: XenServer Count Function

countvoncount

Intro

I’ve been hesitant to dive into XenServer PowerShell cmdlets, but there’s no rational reason to not do it. Citrix continues to make great strides in expanding and updating PowerShell for XenServer, PVS, and XenDesktop. Today, we’ll go over a function that queries an array of XenServer Poolmasters and returns the total VM count on each. The idea behind this function was to stop manually counting VM’s in XenCenter and to understand VM growth and XenServer Pool utilization.

NOTE: Thanks to The Scripting Frog for getting me most of the way there with this function.

xenservercount
The manual count of VM’s

XenServer and PowerShell?

It may seem weird to use PowerShell to perform queries of a Linux-based system, but such is the world we live in. I remember back in my day :). Apple was a joke, IBM ruled the PC market and Linux didn’t exist. Of course I still remember saving BASIC programs to a cassette deck.

th

The script will prompt for credentials which can be root or any XenServer administrator. Then you connect to each pool master in turn…

The important flags are -SetDefaultSession and -NoWarnNewCertificates. You must set the default session on each new XenServer connection, otherwise, the script will not know what pool master to query. The NoWarnNewCertificates flag prevents a prompt asking you to accept the new XenServer certificate (you can leave this out if you want this additional warning to let you know you’re connecting to a new XenServer).

Unless you can refer to your XenServers with a DNS name, you can do some quick translation to make your output more readable. I’m using a switch statement to replace the IP address with a XenServer name.

The rest is just getting all the VM’s (minus snapshots, templates, etc), counting them and putting the results into a custom PowerShell Object. Finally you disconnect from each XenServer and go to the next one.

The results…

XenServer VM Count
--------- --------
XenServerPool1 108
XenServerPool2 109

You can get this and so much more from my github.

Thanks for reading,
Alain Assaf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.