Hi,
I have a simple command which takes around 30 seconds to run using Get-VM:
(Get-VM | Where-Object { $_.PowerState -eq "PoweredOn" }).Count
I decided to try and use Get-View to speed things and and tested the following:
(Get-View -ViewType VirtualMachine -Filter @{"Runtime.PowerState"="PoweredOn"} | Measure-Object).Count
... however it seemed slow.
So I decided to test the most simple of commands:
Measure-Command -Expression { Get-VM }
Measure-Command -Expression { Get-View -ViewType VirtualMachine }
Get-VM took 26 seconds
Get-View took 30 seconds!
This test was conducted in two separate PowerCLI windows (because running get-view after get-vm / vice versa seems to affect times), both having just connected with connect-viserver.
What is going on? :smileylaugh: Anyone have any ideas? :smileyconfused:
Thanks!
Use the Get-View -Property parameter and specify only those properties that you want to retrieve. This will make the Get-View cmdlet much faster.
Regards, Robert
Thanks for your reply 🙂
Brand new PowerCLI sessions for all:
Ran twice:
Measure-Command -Expression { Get-View -ViewType VirtualMachine -Property Runtime.PowerState -Filter @{"Runtime.PowerState"="PoweredOn"} }
Time: 26 seconds and 28 seconds.
Ran once:
Measure-Command -Expression { Get-View -ViewType VirtualMachine -Property Name }
Time: 26 seconds
Confusing. So far no faster. The only time I've seen Get-View be faster is if you've run Get-VM *before* in the same Powershell/CLI session (but then any get-vm will be faster too...).
Do these times stay the same when you fetch properties from the returned objects ?
Pipe the objects to a Select-Object and specify a couple of properties.
The first command in a session always takes a bit longer to execute.
Do these times stay the same when you execute them multiple times in the session ?
Try executing them in a loop.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference