Powershell导入模块找不到模块 [英] Powershell import-module doesn't find modules
问题描述
我正在学习PowerShell,并且正在尝试构建自己的模块库.
I'm learning PowerShell and I'm trying to build my own module library.
我编写了一个简单的模块XMLHelpers.psm1
,并将其放在我的文件夹$home/WindowsPowerShell/Modules
中.
I've written a simple module XMLHelpers.psm1
and put in my folder $home/WindowsPowerShell/Modules
.
当我这样做时:
import-module full_path_to_XMLHelpers.psm1
有效.但是当我这样做时:
It works. But when I do:
import-module XMLHelpers
它不起作用,我得到了错误:
It doesn't work and I get the error:
导入模块:未加载指定的模块'xmlhelpers',因为在任何模块目录中均未找到有效的模块文件.
Import-Module : The specified module 'xmlhelpers' was not loaded because no valid module file was found in any module directory.
我已检查环境变量PSModulePath
包含此文件夹.由于它是网络文件夹,因此我也尝试将其移动到本地文件夹并修改PSModulePath
,但没有成功
I've checked that the environment variable PSModulePath
contains this folder. As it is a network folder, I've also tried to move it to a local folder and to modify PSModulePath
but without success
$env:PSModulePath=$env:PSModulePath+";"+'C:\local'
关于什么可能导致此问题的任何想法?
Any idea on what could cause this issue?
推荐答案
该模块需要放置在与该模块同名的文件夹中.就您而言:
The module needs to be placed in a folder with the same name as the module. In your case:
$home/WindowsPowerShell/Modules/XMLHelpers/
完整路径为:
$home/WindowsPowerShell/Modules/XMLHelpers/XMLHelpers.psm1
您将可以执行以下操作:
You would then be able to do:
import-module XMLHelpers
这篇关于Powershell导入模块找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!