Problem with auto-loading of VMware PowerCLI 6.0 modules

This topic contains 5 replies, has 3 voices, and was last updated by  Vandrey Trindade 2 years, 11 months ago.

  • Author
  • #26846

    Bojan Zivkovic

    Hi, I want to auto-load all PowerCLI 6.0 modules into PowerShell ISE session (or standard PowerShell console). PowerCLI 6.0 was installed under my standard domain account with admin rights on my laptop. However I always run PowerShell console and ISE with run as and use my domain admin account. Having done so path to VMware modules was not automatically added to $env:PSModulePath variable. I created profile.ps1 file with the following content:

    $env:PSModulePath = $env:PSModulePath + ";C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\"
    Connect-VIServer vcenter -User myuser -Password mypassword

    However Connect-VIServer cmdlet has not been recognized i.e. auto-load of VMware modules did not work. When I added line Import-Module VMware.VimAutomation.Core, before Connect-VIServer . . . the latter will work but I do not know why auto-load did not work since path to modules was added to $env:PSModulePath – Import-Module should be redundant step.

  • #26851

    Richard Diphoorn

    There is a known problem with the PowerCLI modules: LINK

    What I do to prevent this is the following:

    # Correcting the Environment Variable to the PowerCLI Module, due to a bug in the PowerCLI installer
            #Save the current value in the $p variable.
            $p = [Environment]::GetEnvironmentVariable('PSModulePath')
            #Add the new path to the $p variable. Begin with a semi-colon separator.
            $p += ';D:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\'
            #Add the paths in $p to the PSModulePath value.
            Import-Module -Name VMware.VimAutomation.Core
            # Connect to the VMware vCenter Server
            Connect-VIServer - Server vcenter -User myuser -Password mypassword
  • #26880

    Bojan Zivkovic

    I have already done that. So Import-Module VMware.VimAutomation.Core is necessary. Pitty, this should be trivial since auto-loading of modules has been there since PowerShell v3. However VMware moved from snap-ins to modules for the first time in PowerCLI 6.0 so this might have something to do with this new concept.

  • #26882

    Richard Diphoorn

    Bojan, maybe here's a clue for you: LINK

    I will try later if autoloading works for me. The code what I posted is for a SMA runbook; so it's PowerShell Workflow.

  • #26883

    Bojan Zivkovic

    Yes, I have already read this but unfortunately in my case Connect-VIServer cmdlet would fail unless module is imported manually.

  • #26927

    Vandrey Trindade

    This is the code I use on my ISE profile (Microsoft.PowerShellISE_profile.ps1) to add the PowerCLI on it:

    #VMware - Logon

    "Connect on VMware PowerCLI", {
    Set-Location "C:\VMware"
    $VMcred = Get-Credential ("$env:USERNAME$")
    Add-PsSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
    Connect-VIServer -Server srv-01, srv-02, srv-03, srv-04 -Credential $VMcred

    #VMware - Logout

    "Disconnect from VMware PowerCLI", {
    Disconnect-VIServer *

You must be logged in to reply to this topic.