Overview

In the past two Get-View posts we’ve talked about what Get-View is and how it works. Some say (including myself) that using Get-View is faster than using other Get-* commands. Well, I decided it was time to put it to the test. Thankfully I had a number of awesome folks from the community that volunteered to run some scripts for me that would generate a CSV for me of how long it took for each command to run. I want to preface this with a few comments:

8 different environments were used (anywhere from home labs to work environments)

Get- Commands were run because we didn’t want to bother anyones environments (some were ok with running a storage re-scan, others opted out as you will see in the charts)

The environments ranged from 5 – 108 hosts and 7 – 1373 VMs

I did not count the number of datastores, vDS, or datacenters in each environment, however I think you’ll get an idea of the performance differences in each of these environments without needing those (although it would have been great of me to get… next time I guess).

So as you can see below, Each environment (X-Axis is the same number throughout the charts/tests) This first image shows us the rough size of each environment.

The first commands we ran were measuring performance between Get-VM and Get-View -viewtype VirtualMachine. as you can see, Get-VM took significantly longer to return all the results, Environment 3 showed the highest increase of 1,249% (if we refer back to the first graph we see that this was with 1373 VMs). Get-VM took 337.35 seconds to execute whereas Get-View only took 25 seconds.

Next was Get-Datacenter vs Get-View -viewtype Datacenter

Although not as significant as the Get-VM results, the Get-Datacenter vs. Get-View results show that there is a 321% difference between the two cmdlets. Even though the max time to return the datacenters was only 1.6 seconds, if you are working on trimming down the duration of scripts, every bit counts.

Get-VMHost vs. Get-View

Get-VMHost took 61% longer to return values than the Get-View equivalent. When solely returning the hosts in a given vCenter, 319 seconds (roughly 5 1/2 minutes) is still significantly greater than the 198 seconds (3 minutes) of Get-View. (The duration specified here was in an environment with 108 hosts, as opposed to the other environments with between 5 – 66 hosts used in these tests.)

Get-Datastore vs. Get-View

Get-VDSwitch vs Get-View

Again, we see that using the Get-* cmdlet’s as opposed to the Get-View format continues to take much longer. The greatest difference in these tests was 1940% (.4 seconds vs 8.16 seconds).

Get-VM | Select Name, NumCPU, MemoryMB, PowerState vs. Get-View

Starting in this test, we measured running the Get-* cmdlet and selecting specific properties from the results. This is a little bias because When running Get-VM and using Select-Object returns all data and then shows only the properties that are specified, whereas Get-View leveraging the -Property parameter, will only search for and return those specific properties, rather than searching all, and returning only a portion. The Get-View method will almost always be faster.

RescanAllHba and RescanVmfs vs. Get-View

This test was an interesting one, because of the nature of the command. This was an optional test for users to run and as you can see in the examples, several users opted out of running these commands. This was set to rescan all HBAs and VMFS datastores, obviously it’s something we discourage from doing in Production, and in a smaller test environment, it is up to the user. The code run is found below:

Running the commands from the API Methods available in Get-View, once again is faster.

Get-VM (IP address, CPUHotAdd) vs. Get-View

The final example I want to show is running Get-VM with a Foreach command, vs. Get-View with a foreach command. This is a little different than previous tests because we aren’t using the view -Property parameter so both commands will return all their data before writing out select properties.

Additional Points

The biggest issue I see customers have with using Get-View, is that, as stated in the Get-View 2: blog post, once invoking Get-View, you are no longer using a VIObject, rather a view object, and other PowerCLI cmdlets do not work off of it. This seems to be the biggest detractor from using Get-View more, however, keep in mind that not only do you have the tasks that can be run off of the view object, the object can also be converted back into a VIObject using the Get-VIObjectByVIView cmdlet, and then running other PowerCLI cmdlets from there.

Data Points

Below is a table of all of the datapoints received for these tests. Each column represents each environment tested (1-8).

Conclusion

As this has probably shown. Get-View commands are going to be significantly faster in returning data and processing commands than the Get-* counterparts. Is there anything wrong with using Get-VM, Get-Datastore, Get-VdsSwitch, etc.? Absolutely not. However, the purpose of this was to allow you to understand how to use the View side of PowerCLI for faster retrievals which can be very beneficial when running time-sensitive monitoring or large scripts.

About Brian Graf

Brian Graf is a Senior Product Manager - Distributed Resource Management (DRS/HA/DPM) at VMware. Previous to Product Management, Brian worked as a Senior Technical Marketing Manager at VMware, focused on PowerCLI Automation and ESXi Lifecycle technologies. Previous roles also include: Consultant for EMC Consulting. His main focus was Data center migration methodologies and implementations. His background previous to VMware includes Operations Engineering, Virtualization, Business Intelligence, and Exchange/Blackberry Engineering. Get notification of new blog postings and more by following Brian on Twitter: @vBrianGraf