Last week we took a look at two new Automated solutions here and here that allows us to leverage vCenter Server and the vSphere APIs to remotely extract information that historically required logging in directly into an ESXi host. While working on the two scripts, I was reminded of another use that could also be really useful which builds on top of some information that I had shared back in 2012. ESXi provides a very basic file manipulation capability that is exposed as a simple HTTPS-based interface.

Here is a quick recap of the three URLs which can be accessed by opening a browser and logging into the ESXi host:

https://esxi-1.primp-industries.com/host

https://esxi-1.primp-industries.com/folder

https://esxi-1.primp-industries.com/tmp

For the purpose of this article, we will be focusing on the first url endpoint /host and below is an example screenshot on some of the configuration files (46 in total) that you would be able to access using this interface.



One of the available ESXi configuration files that you access is the esx.conf file directly where it might be useful to periodically capture the state of this file for either auditing or troubleshooting purposes.

Note: Although esx.conf does contain some amount of the ESXi configurations, it does not represent the full state of the ESXi host. If you wish to perform periodic full backups of your ESXi host (which includes esx.conf by default among other files), there is a vSphere API for this by using the HostFirmwareSystem and the BackupFirmwareConfiguration() method.

Applying the same technique as I have described here, we can easily retrieve the esx.conf for a specific ESXi host being managed by vCenter Server without needing directly login to the ESXi host or worse connecting via SSH. I have created a PowerCLI script called Get-Esxconf.ps1 which just accepts a VMHost object.

Here is an example of how you would use the function and screenshot below of the output:

$esxConf = Get-VMHost -Name "esxi-1" | Get-Esxconf



If you are interested in a specific key within the esx.conf configuration file, we further process the output. The following snippet below searches for the following key /system/uuid and will return the value as it iterates through the esx.conf output.

$esxConf = Get-VMHost -Name "esxi-1" | Get-Esxconf $keyToSearchFor = "/system/uuid" foreach ($line in $esxConf.Split("`n")) { $data = $line.split("=").trim().replace('"',"") if($data[0] -eq $keyToSearchFor) { Write-Host "Key:" $keyToSearchFor write-Host "Value:" $data[1] } } 1 2 3 4 5 6 7 8 9 10 11 $ esxConf = Get - VMHost - Name "esxi-1" | Get - Esxconf $ keyToSearchFor = "/system/uuid" foreach ( $ line in $ esxConf . Split ( "`n" ) ) { $ data = $ line . split ( "=" ) . trim ( ) . replace ( '"' , "" ) if ( $ data [ 0 ] - eq $ keyToSearchFor ) { Write - Host "Key:" $ keyToSearchFor write - Host "Value:" $ data [ 1 ] } }

Hopefully this gave you an idea of just one of the many use cases that can now be enabled through the use of the vSphere API and this ESXi interface. Here are just a few other use cases that I can think of on the top of my mind that could come in handy:

Managing ESXi SSH public/private keys, we have mostly been using httpGet, but you can also use an httpPut to upload these files without needing to go to each and every ESXi host

Replacing Custom SSL Certificates if you are not using VMCA, you can also use an httpPut request to upload these files (you will need to restart hostd or reboot the host for the new SSL Certificates to go into effect)

Quickly access the vpxa.cfg (vCenter Server agent) configuration file for troubleshooting purposes