Powershell Module not loading even after the module path is defined in environment variables

后端 未结 2 1698
粉色の甜心
粉色の甜心 2020-12-19 08:02

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

相关标签:
2条回答
  • 2020-12-19 08:28

    According to documentation available 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 a module is not well-formed, Windows PowerShell does not recognize it as a module.

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

    This is the reason when you made a directory named mod (same base name as the file mod.psm1) and put the module inside it, you could access your cmdlets.

    0 讨论(0)
  • 2020-12-19 08:28

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

    0 讨论(0)
提交回复
热议问题