Powershell import-module doesn't find modules

后端 未结 8 1030
暗喜
暗喜 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)

    0 讨论(0)
  • 2020-12-23 15:35

    The module needs to be placed in a folder with the same name as the module. In your case:

    $home/WindowsPowerShell/Modules/XMLHelpers/
    

    The full path would be:

    $home/WindowsPowerShell/Modules/XMLHelpers/XMLHelpers.psm1
    

    You would then be able to do:

    import-module XMLHelpers
    
    0 讨论(0)
提交回复
热议问题