PowerShell: Add VMware PowerCLI to PowerShell ISE on demand

By | 2014-10-04

I often find my self in need of VMware’s PowerCLI cmdlets, but the PowerCLI console really lack a script editor and IntelliSense support as it builds on the regular PowerShell console.

I could just add the VMware snap-ins to my profile and load them everytime I start PowerShell ISE, but it don’t want to wait for them to load everytime I start it.

Instead I build on my previous post showing how to load your own functions when launching PowerShell (both console and ISE) and create a function to load the snap-ins and initialize the PowerCLI environment that I can call on demand.

function Load-PowerCLI
    Add-PSSnapin VMware.VimAutomation.Core
    Add-PSSnapin VMware.VimAutomation.Vds
    Add-PSSnapin VMware.VumAutomation
    . "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Scripts\Initialize-PowerCLIEnvironment.ps1"

Additionaly I create a function to unload the snap-ins when I no longer need them

function Unload-PowerCLI
    Remove-PSSnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
    Remove-PSSnapin VMware.VimAutomation.Vds -ErrorAction SilentlyContinue
    Remove-PSSnapin VMware.VumAutomation -ErrorAction SilentlyContinue

With those functions in place in my functions folder I can load/unload PowerCLI from any PowerShell instance be that ISE or console. The same approach could easily be taken with any other set of snap-ins, modules etc.


One thought on “PowerShell: Add VMware PowerCLI to PowerShell ISE on demand

  1. Roman

    You’re awesome! Thanks, this was very helpful. Other places, I’ve only seen mention of VMware.VimAutomation.Core, which doesn’t cut it for all of the commands I need to run.


Leave a Reply

Your email address will not be published. Required fields are marked *