[PS] Speedup VMWare PowerShell module

Hi, folks

I am fairly new to VMWare, but I am doing PowerShell now for a couple of years.

My main goal with PowerShell is to get script as efficient as possible, using Help, cmdletbinding, create modules, for repeating tasks,etc.

So as I am new to the VMWare world, I followed the appropriate trainings and exams to get certified for VMWare.

Now I tried to get some scripts up and running using the PowerCli of VMware. The first thing that I noticed is the loading time of the VMWare PowerCli.

This loading time is ridicules long. So I tried to look for a solution to reduce the module loading time.

Where is the module loaded?

To load the PowerCli module a shortcut is placed on the desktop which loads the PowerCli with the following command line

How long does the loading of the module take?

Ok, this takes ages to load, and gives you a bunch of information on your screen that is absolutely of no use to you.

So I started a PowerShell windows and ran a measure-command on the import-module that the shortcut is running.

This took more than 10 seconds to load……………

What does this module do/load?

So I digged into the VMWare.PowerCli module to see what is actually is doing and why it is so slow.

What the module VMWare.PowerCli is doing, it loads all the modules of vmware prior to the load of the module VMWare.PowerCli

Well now we know why VMWare-PowerCli is loading so ridicules slow. VMWare has decided to load all the modules. The question is why…..

When you install the VMWare PowerCli PowerShell modules it installed in C:\Program Files\WindowsPowerShell\Modules

Which is loaded as default PowerShell module folder when you start PowerShell.

This means that whatever command you type PowerShell tries to find and load the appropriate module in that folder. So preloading of the module is unnecessary.

Looked for a solution.

I tried a different approach, only importing the module you actually need. “VMWare.VimAutomation.Core”

To my surprise it only took 893 milliseconds to load, and I have all the commands I need to manage my VMWare virtual machines.

This saved me a little less than 10 seconds.

My approach for my scripts.

So I decided to start my scripts or functions with checking for the VMWare.VIMAutomation.Core module and if is exists in the PowerShell Module Folder load it.

 

I hope this was is helpful for you.

wvsandwijk

I am a Technical Specialist - Cloud Infrastructures from the Netherlands.
My Skills are mainly PowerShell, VMWare, Hyper-V, Microsoft System Center products and Windows Azure Pack.

I work for a company in Utrecht The Netherlands.
Updated: June 11, 2018 — 04:07