Using the same technique as I have described here, you can now also use the vSphere API to connect to vCenter Server to remotely collect esxcfg-info from ESXi hosts without having to SSH'ing to each and every single host. Historically, the esxcfg-* commands were only available in the classic ESX Service Console (COS) and the ESXi Shell. As part of the ESXi transition, VMware has converted all the commands over to the vSphere API which means that you no longer needed to run those local CLIs commands to manage or configure your ESXi hosts like you used to with classic ESX.
The only exception that still exists today is the esxcfg-info command, which still contains a lot of useful information, for some of which is not currently in the vSphere API today. Similiar to the vm-support.cgi script, there is also an esxcfg-info.cgi script which I had blogged about here back in 2011. To output the esxcfg-info, simply open a web browser and specify the following URL with the Hostname/IP Address of your ESXi host:
https://esxi-1.primp-industries.com/cgi-bin/esxcfg-info.cgi
Once you have authenticated with a valid user, you will see that the output matches the output if you were to manually run esxcfg-info command on the ESXi Shell.
Instead of the raw output that you are all probably familiar with, you can also format the output using XML simply by appending ?xml to the end of the URL:
https://esxi-1.primp-industries.com/cgi-bin/esxcfg-info.cgi?xml
With the second formatted option, we can now easily retrieve the result and store that into an XML object for processing using any one of our favorite scripting/programming languages. In the previous article, I demonstrated the use of the vSphere API method AcquireGenericServiceTicket() using a pyvmomi (vSphere SDK for Python) script. In this example, I will demonstrate the exact same use of the vSphere API but now leveraging PowerCLI. I have created a script called Get-Esxcfginfo.ps1 which connects to a vCenter Server and requests a session ticket to a specific ESXi host's esxcfg-info.cgi URL and that will then return us a one time HTTP request to connect to the ESXi host to retrieve the requested information.
Here is an example on how to use the command which will return the XML output which would then require further processing of the XML:
$xmlResult = Get-VMHost -Name "192.168.1.190" | Get-Esxcfginfo
I have also included an example of how to parse the XML return in the script itself. As you can see from the screenshot below, I am extracting the Device Name, Vendor Name & Vendor ID from the esxcfg-info output.
Pretty cool huh? Stay tuned for one more blog post which I will show you another way in which you can make use of this vSphere API!
Schorschi says
Why not make Get-esxcfginfo.ps1 more generic? Show how to pass in parameters? or does the cgi implementation not allow that feature?
William Lam says
The underlying CGI implementation only supports 1 option 🙂
Aaron Longchamps (@Aaron416) says
Do you know if this is adaptable to having a REST call from VMware Orchestrator? I'm asking since there are certain properties not available at all in the vSphere API, but PowerCLI and https://hostName/host/esx.conf do have those properties available.
William Lam says
Aaron,
Yes, given these are just HTTP URLs, you can definitely use vCO or any other solution to perform an HTTP GET
Regarding esx.conf, see my latest blog post 🙂 http://www.virtuallyghetto.com/2016/06/using-the-vsphere-api-to-remotely-collect-esxi-configuration-file-esx-conf.html
Aaron Longchamps (@Aaron416) says
I did see that post, but had issues setting the cookies. I can do everything else with code (add REST host, REST operation, get auth token) but didn't find a way to set cookies in vRO 6 REST. Do you have any pointers on that? Thanks!
Jayaraghavendra says
Hi
I was looking to get the details of storageHeap and below 10 lines like below;
|----Name............................................storageHeap
|----Growable........................................true
|----Max Size........................................62763864 bytes
|----Max Available...................................57474368 bytes
|----Current Size....................................11539288 bytes
|----Current Allocation..............................5289496 bytes
|----Current Available...............................6249792 bytes
|----Current Releasable..............................0 bytes
|----Percent Free of Current.........................54
|----Percent Free of Max.............................91
|----Percent Releasable..............................0
is this possible to get ?? If yes any chance how from your script?
Thanks in advance.
Deepali says
Hi William,
great work making the large output of esxcfg-info available remotely through browser.
I want to know if there is any cli command or an API that will give me the a more elaborate list of smart parameter values of physical disks on the host.
Would appreciate your response.
Thank you
Dee