On the VI Toolkit blog there’s a great article for people like me. They explain how to speed up your scripts. I’m no powershell guru, and these kind of articles are more than welcome to boost my scripting skills.
In short, it comes down to these three tips:
- Try to load as many objects as possible into arrays beforehand. Once you’ve got them loaded you can use them as arguments to multiple calls without having to resort to potentially expensive lookups every time.
- Just like in sample 1 above, when you’ve loaded objects, use the objects directly rather than using their names. This is usually not hard as our cmdlets are designed to take object first-and-foremost, and names are supported just as a convenience.
- If you absolutely need to load a single VM object by name, load it using the Get-VMFast function below. While this approach can certainly help, it’s not nearly as good as using the other two techniques mentioned above.
Head over to the VI Toolkit blog and start reading.