Many of the VI Toolkit scripts I've been writing end up needing to do something like this:
Get-VM -Name "vmname" | Get-View | etc
For whatever reason I constantly have to Get-View to get anything of value out of the script. For anyone that is in a reasonably large environment knows this is fairly slow. My co-worker goes to me and says "Why don't you just skip the Get-VM and use Get-View directly?" Ya know that's a pretty smart idea so I do this. I'm blown away at how much of a difference this is so I go and time the script I'm using.
Using the command Get-VM -Name "vmname" | Get-View takes 1 minute and 37 seconds to run. Ugh.
Using the command Get-View -ViewType VirtualMachine -Filter @{"Name" = "vmname"} takes.. Wait for it
Wait for it
Wait for it
5.12 seconds!
Yes. I'm not making this up. The question I've got for the VI Toolkit/Powershell wizards out there is WHY!!!???
Attached is the script I used for testing. Yes its not the world's best as its only my 3rd custom written script to date though I will take recommendations in private messages or a different topic to make it better,nicer,faster,cooler,more powershell like.