11 Replies Latest reply on Aug 4, 2017 11:17 PM by grasshopper

    PowerCLI 6.5.x - Import-Module when executed via an C# and ASP.net fails with command was found in the module but the module could not be loaded

    vMan Enthusiast

      So this one is interesting...

       

      I have a self-service portal which I built for users to pull metrics from vRops, It runs on W2K12, C# / ASP.net and executes a PowerShell script which goes off and talks to the vRops API and vCenter for Event history...

       

      The portal has been working just fine using PowerCLI 6.3 R1, I recently upgraded to PowerCLI 6.5.1 and had customers complain that the Events where no longer showing up in the report... When I execute the script via PowerShell manually or with a Scheduled task it works just fine and events are imported... but when the ASP page runs the script it fails!

       

      So after lots of playing around I discovered that Import-Module appears not to work correctly when executed by my webpage... where as Add-PSSnapin still works just fine. The portal runs as a Domain User which is also an administrator of the server...

       

      I suspect it's permission related as I found this post that sounded like a similar issue...

       

      Has anyone else experienced this before?

       

      Connect-VIServer : The 'Connect-VIServer' command was found in the module 'VMware.VimAutomation.Core', but the module could not be loaded. For more information, run 'Import-Module VMware.VimAutomation.Core'.

      At E:\vRops\vRopsScript.ps1:506 char:1

      + Connect-VIServer -server $VC -User $vRopsUser -Password $vRopsPasswor ...

      + ~~~~~~~~~~~~~~~~

          + CategoryInfo          : ObjectNotFound: (Connect-VIServer:String) [], CommandNotFoundException

          + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

       

      Could not load file or assembly 'file:///E:\vROPS\Modules\VMware.VimAutomation.Common\6.5.1.5335010\Common.Logging.dll' or one of its dependencies. The system cannot find the file specified.

      Import-Module : Could not load file or assembly

      'file:///E:\vROPS\Modules\VMware.VimAutomation.Common\6.5.1.5335010\Common.Logging.dll' or one of its dependencies. The system cannot find the file specified.

      At E:\vRops\vRopsScript.ps1:501 char:1

      + Import-Module VMware.VimAutomation.Core -Force

      + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

          + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileNotFoundException

          + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand

       

      Could not load file or assembly 'file:///E:\vROPS\Modules\VMware.VimAutomation.Common\6.5.1.5335010\Common.Logging.dll' or one of its dependencies. The system cannot find the file specified.