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.