How Can We Help?
< Back
You are here:

Limit cmdlet calls in a loop

While it is perfectly alright to run a loop in the following way.

You can improve the runtime of your script by using just one call to the Get-Stat cmdlet.

Instead of having to deal with the overhead of the Get-Stat cmdlet multilpe times, in the second snippet, the Get-Stat cmdlet is only called once. The script uses the Group-Object cmdlet to split out the results per VM.

The second snippet still has room for improvement.
You can skip the VMs that are not powered on and only obtain the aggregate data, if that fits the requirement.


Previous Use lookup tables

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Table of Contents