VMware Cloud Community
iguy
Enthusiast
Enthusiast
Jump to solution

Speed using Get-VM vs Get-View

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.

0 Kudos
1 Solution

Accepted Solutions
andrey_anastaso
Enthusiast
Enthusiast
Jump to solution

Hi, Ian,

Can you verify that you're using VI Toolkit 1.0 Update 1 (v.1.0.1). Between 1.0 and 1.0 Update 1 we took some (limited) measures to improve Get-VM's speed. So if you're on 1.0.0, upgrading to 1.0.1 will relieve your problem a bit.

Basically, the reason why "Get-VM" is significantly slower than "Get-View -ViewType VirtualMachine" is that the VM object is quite bulky and contains much more data than the view.

A slow Get-VM is clearly a serious problem as it is easily the most frequently invoked cmdlet. So we're looking at ways to address the problem.

One of the biggest measures we're taking is in delegating the by-name filtering to the server. So when you call Get-VM "vmname" the server would send a single VM. This optimization relies on a feature which is new to VC 4.0. The bad news is that it will be quite some time before we release the version which has this optimization.

Meanwhile, we're looking at ways to reduce the size of the VirtualMachine object by removing some of the nested objects such as VMGuest and the virtual devices. The biggest obstace to this change is the need for backward compatibility. So it's not completely straightforward but I think we'll be able to find an accepbable compromize.

View solution in original post

0 Kudos
6 Replies
halr9000
Commander
Commander
Jump to solution

Glad you found those get-view parameters. But let's redirect this question to where it belongs. VMware would do well to answer why the vast difference in performance.

PowerShell MVP, VI Toolkit forum moderator

Author of the upcoming book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Whoooo thats amazing, what is going on with get-view then VMware ? This might even make my reporting script seam faster :smileylaugh:

If you found this information useful, please consider awarding points for Correct or Helpful.

Alan Renouf

VMware, Citrix, Microsoft Consultant

UK

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
andrey_anastaso
Enthusiast
Enthusiast
Jump to solution

Hi, Ian,

Can you verify that you're using VI Toolkit 1.0 Update 1 (v.1.0.1). Between 1.0 and 1.0 Update 1 we took some (limited) measures to improve Get-VM's speed. So if you're on 1.0.0, upgrading to 1.0.1 will relieve your problem a bit.

Basically, the reason why "Get-VM" is significantly slower than "Get-View -ViewType VirtualMachine" is that the VM object is quite bulky and contains much more data than the view.

A slow Get-VM is clearly a serious problem as it is easily the most frequently invoked cmdlet. So we're looking at ways to address the problem.

One of the biggest measures we're taking is in delegating the by-name filtering to the server. So when you call Get-VM "vmname" the server would send a single VM. This optimization relies on a feature which is new to VC 4.0. The bad news is that it will be quite some time before we release the version which has this optimization.

Meanwhile, we're looking at ways to reduce the size of the VirtualMachine object by removing some of the nested objects such as VMGuest and the virtual devices. The biggest obstace to this change is the need for backward compatibility. So it's not completely straightforward but I think we'll be able to find an accepbable compromize.

0 Kudos
alanrenouf
VMware Employee
VMware Employee
Jump to solution

Thats one of the nicest things about working with VMware - they read there own forums and give you straight answers. Thanks Andrey, I for one appreciate the work you are doing on the VI Toolkit.

Blog: http://virtu-al.net Twitter: http://twitter.com/alanrenouf Co-author of the PowerCLI Book: http://powerclibook.com
0 Kudos
iguy
Enthusiast
Enthusiast
Jump to solution

I am using Powershell CTPv2 & VMware-Vim4PS-1.0.0-113525. This is the latest version I can download off of the VMware download site.

Thanks for the answer. This information would be useful to know going foward in the API or docs at least. I know it violates the readability of the scripts which is one of PowerShell's claim to fame. Though a difference in performance of this warrants knowning it in the API call.

i.e.

Get-Help Get-VM

Get-VM gets a ton of very useful data when you are looking for the bare basic information around a VM. However if you are digging deeper into properties of that VM you might want to use Get-View -ViewType VirtualMachine instead to get a View quicker.

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi,

One other thing that might be worth trying is Get-View -ViewType VirtualMachine -Filter @{"Name" = "vmname"} | Get-VIObjectByVIView. This will give you the same object that Get-VM vmname does.

I would be curious to see if that is faster than just Get-VM vmname. One way to speed up Get-View even more is to add -property config (which causes only a subset of the view to be returned).

One other thing to note is that using Get-View in this way will return all VMs with vmware in the name, you can add ^ to anchor to the front of the name and $ to anchor to the back. I'm not sure if you can do wildcard matching the way Get-VM does it.