Powershell module does not load even after the module path is defined in environment variables

I have a module in the folder that I created, C: \ PowerShellScripts \ Modules. I call it mod.psm1. This file contains two simple functions: Write-hello and Write-bye.

Now I have added this path (C: \ PowerShellScripts \ Modules) to my PSModulePath environment variable path.

Accordingly, this should automatically load the module when PowerShell starts. Right?

But when I start PowerShell and try Write-hello or Write-bye, it gives an error

write-hello: the term "write-hello" is not recognized as the name of a cmdlet, function, script file, or operating program

PowerShell does not load the mod.psm1 file, although $ ENV: PSModulePath shows my path (C: \ PowerShellScripts \ Modules)

And I need to use Import-Module again manually. What could be wrong?

+3
source share
2 answers

I get it. I needed to add the mod.psm1 file to a folder named "mod". Now I can directly access my write-hello or write-bye cmdlets when I start PowerShell.

+2
source

According to available documentation here
A β€œwell-formed” module is a module that is stored in a directory that has the same name as the base name of at least one file in the module directory. If the module is not correct, Windows PowerShell does not recognize it as a module.

The "base name" of a file is a name without a file name extension. In a well-formed module, the name of the directory containing the module files must match the base name of at least one file in the module.

It is for this reason that you created a directory called "mod" (the same base name as the mod.psm1 file), and placed the module in it, you can access your cmdlets.

+10
source

Source: https://habr.com/ru/post/982858/