PowerCLI

 View Only
  • 1.  Load PowerCLI modules from within a module function

    Posted Jan 17, 2017 03:11 PM

    I have a personal module with a bunch of commonly use functions.  Since I can never remember the syntax for loading the PowerCLI modules or how to silently connect to vCenter instance (without all the yellow error messages), I thought I would write a function to do it all for me.  I see the function just fine (my module auto-loads and I can get-help on my function), but the modules seem to fall out of scope after the function completes, so they are not available to me to start using PowerCLI commands in my PowerShell session.  I don't want PowerCLI to load every time I start ISE since it takes long to load and connect - I only want them available at specific times and hence I thought a could use a function to automate the process.

    Is there a way to load modules that exist during the entire PowerShell session from a function called from a module?  Or for that matter, why can't PowerCLI auto-load like every other module?

    Thanks

    NK



  • 2.  RE: Load PowerCLI modules from within a module function
    Best Answer

    Posted Jan 17, 2017 05:22 PM

    The lack of auto-load of the current PowerCLI modules is known, and is historical.
    I suspect this will be fixed eventually.

    You could put this in one of your profile files

    Get-Module -Name VMware* -ListAvailable | Import-Module -Scope Global



  • 3.  RE: Load PowerCLI modules from within a module function

    Posted Jan 17, 2017 08:14 PM

    Thank you.  I added "-Scope Global" to the loading of the PowerCLI modules in my function and now it works.

    NK