Powershell speed – Get-VM vs. Get-Type -ViewType

I’ve been starting to look at using the VI Toolkit which uses Powershell.   In doing this many of the command formats tend to be “Get-VM | Get-View” or “Get-VMHost | Get-View“.   So I’m off and figuring this out and I run a small script and say “Geez that took a long time to run”.   I’m talking to my co-worker (a pretty smart cookie) and he says “Why don’t you just use “Get-View -ViewType VirtualMachine” and skip the middle man?”   Good point.  Didn’t know about that command.  Well this is just a tad bit faster.

Get-VM | Get-View timing in my script takes 1 minute and 37 seconds.

Get-View -ViewType VirtualMachine takes an amazing 5.12 seconds.

The VI Toolkit developers have identified this as a serious issue are working on ways to speed this up and retain backwards compatibility.

So the lesson today is if you need to do a Get-View immediately after doing some set collection look at using the Get-View -ViewType instead.  It isn’t as readable though it gets the job done well.

Posted on December 12, 2008 at 6:06 pm by iguy · Permalink
In: VMware · Tagged with: , , , ,

4 Responses

Subscribe to comments via RSS

  1. Written by Mike DiPetrillo
    on 13 December 2008 at 1:15 am
    Permalink

    Great find. Back in college I was writing a program to play checkers against a human. My professor looked at my program and saw all of these nested if statements and laughed at me and showed me what the correct answer was for how to write the program. Sure his was more advanced but mine ran 10 times faster. Just goes to show there’s always a better mouse trap and sometimes it’s as simple as a sledgehammer. :)

  2. Written by Cody
    on 28 December 2008 at 4:37 am
    Permalink

    Indeed. Does this also return the same object back to the pipeline that a get-vm does?

  3. Written by iguy
    on 29 December 2008 at 2:05 am
    Permalink

    It returns a Get-View object. Its not the same ton of associated properties and objects.

    My point in the post is that a significant number of scripts perform the same exact action and that being “Get-VM | Get-View | etc..” However Get-VM is significantly slow if you are just going to go to Get-View immediately afterwards.

    If your script goes and says “Get-VM | Get-View” then you should do a “Get-View -ViewType VirtualMachine”. If you have other things your going to do with a Get-VM then this might not be the best solution for you.

  4. [...] slow compared to pulling useful data from it. I’ve done performance testing before of Get-VM against Get-View to get to the useful data needed day to day.   In that test using Get-View was [...]

Subscribe to comments via RSS

Leave a Reply