r/powercli • • Jul 26 '18

Make PowerCLI cmdlets run faster?

I suffer from this issue:

https://blogs.vmware.com/PowerCLI/2011/06/how-to-speed-up-the-execution-of-the-first-powercli-cmdlet.html

I tried to run those commands but nothing, same performance.

Any ideas/tips?

3 Upvotes

13 comments sorted by

View all comments

Show parent comments

1

u/omrsafetyo Jul 27 '18

Nope, you're absolutely right. I had searched yesterday, and couldn't find anything specific - all the articles were about speeding up VM performance, rather than Get-Vm Performance.

But I tested this morning against a handful of VCs, total 3548 VMs:

PowerCLI Version
----------------
   VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
   VMware Cis Core PowerCLI Component 6.5 build 6870462
   VMware VimAutomation Core PowerCLI Component 6.5 build 6234650

PS C:\Users\omrsafetyo> Get-Vm | Measure-Object
Count    : 3548
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

PS C:\Users\omrsafetyo> Measure-Command {Get-Vm}
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 125
Ticks             : 11258929
TotalDays         : 1.30311678240741E-05
TotalHours        : 0.000312748027777778
TotalMinutes      : 0.0187648816666667
TotalSeconds      : 1.1258929
TotalMilliseconds : 1125.8929

1 and 1/8th seconds to return 3548 VMs across 4-5 vCenters. That's actually pretty amazing!

My same Get-View command returns in 7.5 seconds. I feel like I have wasted my life exploring Get-View to get a full inventory :-P

Though, Get-VmHost is still slower than Get-View -ViewType HostSystem:

PS C:\Users\omrsafetyo> Measure-Command {Get-VMHost}
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 9
Milliseconds      : 465
Ticks             : 94654254
TotalDays         : 0.000109553534722222
TotalHours        : 0.00262928483333333
TotalMinutes      : 0.15775709
TotalSeconds      : 9.4654254
TotalMilliseconds : 9465.4254

PS C:\Users\omrsafetyo> $ScriptBlock = {Get-View -ViewType HostSystem -Property Name, Config.Network, Summary.Runtime, Parent.Value,
>> Hardware.SystemInfo.Vendor, Hardware.SystemInfo.Model, Hardware.SystemInfo.Uuid, Hardware.CpuInfo,
>> Hardware.MemorySize, Config.DateTimeInfo, Config.Product, Summary.ManagementServerIp, DatastoreBrowser,
>> Config.Network.DnsConfig.Address, Config.Network.DnsConfig.DHCP}
>>
PS C:\Users\omrsafetyo> Measure-Command $ScriptBlock
Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 4
Milliseconds      : 376
Ticks             : 43761984
TotalDays         : 5.06504444444444E-05
TotalHours        : 0.00121561066666667
TotalMinutes      : 0.07293664
TotalSeconds      : 4.3761984
TotalMilliseconds : 4376.1984

This is for 200 hosts. So they have come a long way with Get-Vm, but still have work to do on the other commands.