Getting an ESX host’s version from the host

A co-worker asked me the other day how to get the version of an ESX host from the host itself (the service console). I told him to look at /etc/vmware-release, but he said that that wasn’t enough information. The next day another co-worker asked if it is possible to tell the difference between a vCenter server and an ESX host without authenticating to either. I said, sure, the RetrieveServiceContent method does not require authentication. Then it occurred to me you can use the same thing locally on an ESX host to determine the exact version of the host.

Since ESX <4 hosts do not have cURL on them, it was up to Perl to do the job. Here is the Perl that you can execute from the service console that will print out the full version of the ESX server you are executing from:

use strict; 
use LWP::UserAgent; 
use HTTP::Request::Common; 

my $userAgent = LWP::UserAgent->new(agent => 'perl post'); 
my $message = '
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">
		<retrieveservicecontent xmlns="urn:vim25">
			<_this type="ServiceInstance">ServiceInstance

my $response = $userAgent->request( POST 'http://localhost/sdk/webService', 
									Content_Type => 'text/xml', 
									Content => $message); 

if ($response->content =~ /<fullname>([^<].*)<\/fullName>/) 
	print $1;

And for your convenience, here is the same Perl properly escaped so that it can execute on the command line in a single command:

perl -e "use strict; use LWP::UserAgent; use HTTP::Request::Common; my \$userAgent = LWP::UserAgent->new(agent => 'perl post'); my \$message = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"\" xmlns:xsd=\"\" xmlns:xsi=\"\"><soapenv:Body><RetrieveServiceContent xmlns=\"urn:vim25\"><_this type=\"ServiceInstance\">ServiceInstance</_this></RetrieveServiceContent></soapenv:Body></soapenv:Envelope>'; my \$response = \$userAgent->request(POST 'http://localhost/sdk/webService', Content_Type => 'text/xml', Content => \$message); if (\$response->content =~ /<fullName>([^<].*)<\/fullName>/) {print \$1;}"

Hope this helps!

Update 1

Before someone point out the obvious, I did not display the result of the script. It will look something like this: VMware ESX Server 3.5.0 build-64607


Leave a Reply

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

You are commenting using your 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