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

XenServer: Change Root Password

keep-calm-and-change-your-xenserver-password-3

Intro

Your boss comes to you in a panic about security and passwords. You sip your coffee and calmly let her vent. You assure her that yes, you can quickly and easily change the root password on all your XenServers. She walks away confident you know what you are talking about.

Change that password…or can you?

You hit the Internet for information on changing the XenServer root password and are hit with article after article about recovering a lost root password. That doesn’t apply to you. You have your root password safely stored in your password store (right :)).

You ask yourself, “Self, where are the instructions on changing the root password when you already know it?

A quick look at the XenServer install guide and admin guides don’t reveal anything either.

Yes you can

Citrix support wasn’t much help in this, but the answer is quick and easy, especially if you have XenServer pools.

First connect to your XenServer (use the Pool Master if you have a pool), and get to the console.
xenserver1

Select Authenticationxenserver2xenserver3

Select Change Passwordxenserver4

Authenticate with your current password (if prompted).xenserver

Enter the old password, followed by the new password twice.xenserver7

Once you hit enter, the system will change the password.xenserver8
And you’re done.xenserver9

BONUS: If you changed the password on the Pool Master, this will change the root password on all the pool member servers.

Thanks for reading,
Alain

PowerShell: XenServer 6.0 CmdLet Poster

Fire up your large format printers!

The fine folks at X-Tech have put together an exhaustive (and large) poster showing all the existing and new cmdlets for managing XenServer through PowerShell.

An Example of the  XenServer cmdlet poster
An Example of the XenServer cmdlet poster

Get your copy here.

Thanks,
Alain