Not sure when and how this drive to optimize appeared in me, but I've seen it taking control in different situations and driving other people crazy. So I thought why not give it a try on the blog also. Maybe something good comes out of it.
I will go over a couple of simple concepts that will help with the execution of PowerCLI scripts. The first one is API calls and to be more specific the number of calls.
Let's use the following example:
- we have a list of VMs and we need to get the total used space by those VMs
- get the size for each VM from the list and make the sum
- get all VMs in vCenter Server and then check each VM in the list
- calling the API is expensive - 1 call is better than 10 calls
- imbricated loops are not scalable (not even nice)
- hash tables can help