Sunday, February 28, 2016

PowerShell - Import Module fails

I was trying to run a PowerShell command to connect to my azure instance and to my surprise the PS engine reported back error stating it can not find the command.. Interesting..

I started investigating what happened and tried importing the module directly and PS again threw an error:

Import-module : The specified module 'acbc' was not loaded because no valid module file was found in any module
directory.
At line:1 char:1
+ import-module acbc
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (acbc:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Now this was shocking.. the next obvious thing was to check the PowerShell module path in the System Environment to see if the module path includes the module i was trying to import..

here's the command to check the PS module path quickly

$env:psmodulepath

So, i checked the output and can see the module present but still i can't load it? hmm, now its really getting confusing..

I then ran Get-Module -ListAvailable and it just showed be VMware module only..huh!

so, i checked the environment variable under computer settings and found a PSMODULEPATH variable under user settings which was overriding system environment variable..

here's the quick fix:

Copy the path from the User Environment Variable to System Variable.. and remove the User variable. :)

or

Copy the PSmodules path to your User Environment variable if you want modules to be available to your account only.



No comments:

Post a Comment