Speed Comparison – VMHost Models

You may know by now that in PowerCLI there are a couple of ways to get information such as ESX host details using predefined cmdlets such as:

$vmhost = Get-VMHost

There is also another way using the Get-View cmdlet

$vmhost = Get-View -ViewType HostSystem

Depending on the information you require and the size of your environment the time these commands take to run could be siginificant.
Timings in seconds:

Get-VMHost : 33.5733573
Get-View   : Exception of type 'System.OutOfMemoryException' was thrown.

Or in the case of my Production environment error out due to lack of memory in the Powershell. Note to self: Find out how to increase the memory space.

Get-VMHost gets a subset of all available information. Get-View gets a larger amount of data.
For the purposes of my current task I only want information on a particular Model of host. In this case I am only interested in HP DL380 servers.

$vmhost = Get-VMHost | ? { $_.Model -match "ProLiant DL380" }
$vmhost = Get-View -ViewType HostSystem -Filter @{"Hardware.SystemInfo.Model"="ProLiant DL380"}

Timings in seconds:

Get-VMHost : 35.5198533
Get-View   :  8.6454952

So why do I care about Get-View vs Get-VMHost?

For the most part I use PowerCLI to do reporting. As I have a large number of reporting scripts and I am only retrieving information, almost all the information I am after I can retrieve via Get-View.
In the above example above I have saved 27 seconds in just one command. With a large number of commands in my reporting scripts these precious seconds add up to significant time savings. More importantly by refining the information requested, the load on the vCenter servers is reduced.

I am only at the start of my Get-View journey. Most of my current scripts need to be re-written as some are many years old now and are a historical recording of my learning process in Powershell and PowerCLI. So over time it will be very interesting to convert all of these scripts and see the total time changes I can affect.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.