Powershell import-module doesn't find modules

后端 未结 8 1074
暗喜
暗喜 2020-12-23 14:45

I\'m learning PowerShell and I\'m trying to build my own module library.

I\'ve written a simple module XMLHelpers.psm1 and put in my folder $home/

8条回答
  •  一整个雨季
    2020-12-23 15:34

    I experienced the same error and tried numerous things before I succeeded. The solution was to prepend the path of the script to the relative path of the module like this:

    // Note that .Path will only be available during script-execution
    $ScriptPath = Split-Path $MyInvocation.MyCommand.Path
    
    Import-Module $ScriptPath\Modules\Builder.psm1
    

    Btw you should take a look at http://msdn.microsoft.com/en-us/library/dd878284(v=vs.85).aspx which states:

    Beginning in Windows PowerShell 3.0, modules are imported automatically when any cmdlet or function in the module is used in a command. This feature works on any module in a directory that this included in the value of the PSModulePath environment variable ($env:PSModulePath)

提交回复
热议问题