1

I am attempting to create a custom PowerShell module and have included in a new directory called MyModule a .psm1 module file with a few simple functions and a .psd1 manifest file. This directory is stored in one of the locations specified in $env:PSModulePath.

When I attempt to import the new module I get the following error:

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

The directory I am calling Import-Module on has the same name as the psm1 file as well.

Directory: C:\MyModule

Mode                LastWriteTime         Length Name                                                                                                                                                                           
----                -------------         ------ ----                                                                                                                                                                           
-a----         9/3/2016   1:40 PM           2595 MyModule.psd1                                                                                                                                                                  
-a----         9/3/2016   1:06 PM           1718 MyModule.psm1  

I have been using the following resource as a guide: https://msdn.microsoft.com/en-us/library/dd878324(v=vs.85).aspx

What am I missing?

Thank you in advance.

1 Answer 1

2

The directory that's in PSModulePath needs to contain one or more directories which match the module name. In other words, C:\MyModule should not be explicitly in the PSModulePath, instead you should add something like C:\PSModules to the path, then within that directory, you'd have \MyModule which contains your module and manifest.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.