In this Speed Comparison I am reporting on the number of each ESX version I have in my environment to generate a report like the one below.

This table is not really a good example of a standardised environment I admit. However this is the reality of the real world large enterprise.
These timing tests were run against a vCenter with three (3) clusters of eight (8) hosts.
Old Way
#Get list of all the esx hosts
$vmhostlist = Get-VMHost
#Create ESXi Version count report
$esxiversions = $vmhostlist | ? { $_.Extensiondata.Config.Product.ProductLineId -eq "embeddedEsx" } | Select Name, Version, Build | Group Build | Select Count, @{Name="Version"; Expression={$_.Group[0].Version} }, @{Name="Build"; Expression={$_.Name} } | Sort-Object Build -Descending
Timings
Task : Seconds $vmhostlist : 6.3 $esxiversions : 35.4
New Way
#Define variable script blocks for Select-Object
$esxtype = @{Name="ESX"; Expression={$_.Config.Product.ProductLineId} }
$version = @{Name="Version"; Expression={$_.Config.Product.Version} }
$build = @{Name="Build"; Expression={$_.Config.Product.Build} }
#Get list of all the esx hosts
$vmhostlist = Get-View -ViewType HostSystem -Property Name, Config.Product.ProductLineId, Config.Product.Version, Config.Product.Build -Filter @{"Config.Product.ProductLineId"="embeddedEsx"}
#Create ESXi Version count report
$esxiversions = $vmhostlist | Select Name, $esxtype, $version, $build | Group Build | Select Count, @{Name="Version"; Expression={$_.Group[0].Version} }, @{Name="Build"; Expression={$_.Name} } | Sort-Object Version -Descending
Timings
Task : Seconds $vmhostlist : 3.7 $esxiversions : 0.008
Production Results
These are the core components of a reporting script that runs against my entire environment. 950+ ESXi Hosts. Using the old way this report takes 16.5 minutes. Using the new way 27 seconds.
Whilst this approach does make the script a little more convoluted, it clearly demonstrates the power of refining your search criteria to just the information required.
Permalink
Small typo in New Way – $esx should be $esxtype in line 10 – references the defined variable on line 2. Otherwise, very cool and very interesting
Permalink
@someguy
Thank you. Will correct right now.