ESXi Host Serial Number with PowerCLI (v5.0 or later)
I was recently asked to pull serial numbers for each of the ESXi hosts in my environment. I initially assumed that this would be a property in the VMHost object in PowerCLI, and would thus be a trivial task.
Guess what? It isn’t.
PowerCLI> Get-VMHost | Get-Member -MemberType Property | select Name Name ---- Parent NumCpu PowerState ParentId Model MemoryUsageMB NetworkInfo Name ProcessorType VMSwapfileDatastore Version VMSwapfilePolicy VMSwapfileDatastoreId StorageInfo State Uid TimeZone MemoryUsageGB CustomFields CpuUsageMhz ExtensionData DiagnosticPartition Build ApiVersion CpuTotalMhz ConnectionState FirewallDefaultPolicy MaxEVCMode Manufacturer MemoryTotalMB MemoryTotalGB Id HyperthreadingActive LicenseKey IsStandalone
Hardware serial number is one of those “I could have sworn I saw it here once” properties that isn’t actually available.
Some Google searching yielded a few different approaches to solve for this question. From what I found, they seem to either pull the serial number from a vSphere View of each host, or from some out-of-band management system (such as HP iLO). Unfortunately, for reasons that are not important, neither of these methods worked for me.
It turns out, though, that there is a way to get the serial number using esxcli:
esxcli hardware platform
Since PowerCLI 5.0, you can make calls to esxcli using the Get-EsxCli
cmdlet. If you combine this with the very powerful New-VIProperty
cmdlet, you can actually add the serial number to the VMHost object, and thus to the output of Get-VMHost
.
New-VIProperty -ObjectType VMHost -Name SerialNumber -Value ` { (Get-EsxCli -VMHost $Args[0]).hardware.platform.get().SerialNumber } Get-VMHost | Select Name,SerialNumber
Not exactly a high-performance solution, but as long as your hosts are all at ESXi 5.0 or later, it works!
Special thanks to Luc Dekens for his valuable New-VIProperty
insights.